I have web-application.
When I follow a link:
http://..... document/view?type=pdf
I expect browser to show a pdf file. It works correct on Firefox and IE, but Chrome starts downloading it instead of showing.
Here is the code:
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline; filename=test;");
OutputStream out = response.getOutputStream();
out.write(pdfByteData);
out.flush();
What could be the problem? May be it is because of my local chrome settings or something else? I have no idea.
Try to install the pdf plugin in chrome using the following link
https://support.google.com/chrome/answer/142056?hl=en
How Browsers Work With File Downloads
Usually when a user goes to a file URL (for example: a download link), the file will show in the
browser if the browser supports it. Image files like jpg, png, gif
etc. will almost always show in the browser. Archive files like zip,
tar, gzip etc. will always be downloaded. Some file types show up in
some browsers but not others depending of if the browser can read the
file or not. For example, Internet Explorer (IE) will usually try to
show Microsoft Word files (doc and docx) in the browser, while most
other browsers will download it. Google Chrome has its own PDF
converter and it will try to convert a PDF file and render it in the
browser.
The key thing to understand is that some browsers maybe able to read a
particular file type based on the addons you have installed for that
browser while others may not be able to. If a browser can read the
file type it will show it in the browser. If the browser cannot read a
file type it will force a download to the hard disk. Usually this is
not an issue since the users can save the file to there computer after
it is shown in the browser.
Just use HTML command, this what i did to my website :
Click Here to view the PDF file
works in every browser !.
Related
I'm currently implementing an Angular/java webpage to work with different forms for the users.
right now if the users want to edit the pdf, the only way is to download the PDF and go to the downloads folder and open it in Adobe acrobat. Which is not an optimal solution.
Is there any way I can create a button in HTML/Angular webpage that can automate this process to open the PDF in Adobe acrobat? instead of downloading and going to download folder and open it from there?
I tried to use ngx-extended-pdf-viewer to edit the pdf in the browser. But the user needs to highlight, stamp, and email features that are in Acrobat. Does anyone have a solution for this?
thanks
You can display the pdf file in new tab by the line:
window.open(fileUrl, '_blank');
The fileUrl is a variable that contains the file path. You can fetch it after the download is complete.
I have a URL that causes a web server to generate a PDF when opened. Is it possible to save this PDF document to disk (client side), using Java? I found lots of examples for doing this when the PDF already exists as a document on the web server, but the code for these examples does not seem to work in the case where the web server doesn't begin to create the content until the link is opened (at least that is my impression at this point).
There is a link that I can click to produce the PDF. The HREF for that link is:
<a href="javascript:open_window('ReportDisplay.cfmincidentID=223189&cs=377041B‌​A2467C3CEA7FD989A12126E0E&services=2815&format=1&UniqueID=651F76E4E56‌​91207B9B2AF1F51A780AA')">
<img src="../../Images/pdf-small.gif" alt="Report" border="0" height="15" width="15">
</a>
I construct a complete URL, including the protocol and such, and I can paste that complete URL into the location bar of the browser. This does in fact produce the PDF in the current window. So, this is what I'm trying to capture into a file on my local disk.
You are currently serving the PDF inline whereas you want to change it as an attachment. See the answer to the question Content-Disposition:What are the differences between "inline" and "attachment"? to find out what's the difference.
If you use the Content-Disposition header "inline", the PDF will be shown in a browser window. If you use Content-Disposition header "attachment", a dialog box will open, asking the end user where he wants to save the PDF.
You can't "automatically" save the PDF on the end user's machine because you don't have any idea about the operating system and the disk organization of the end user. If he's on Windows, the path C:/temp will probably exist, but if he's on a Mac or a Linux machine, that path won't exist. That's why you'll always need a "Save as" dialog on the client side.
I have simple code to execute commands from cmd in windows xp
I would like to display output in IE and Chrome browser instead of notepad
Thank you for the tips,
PrintWriter output = new PrintWriter(
("C:\\Documents and Settings\\jszpakow\\Desktop\\ping.txt"));
thank you very much for advices. I'm new here so I know in the future I should be more specific. it's nothing wrong with notepad++, or browser as a text viewer (however when I create html text is not raw like in notepad)
My idea was not to open each time CMD and copy ping output to my case notes which is in web browser system (based on Liferay)
My problem is that I need to paste this ping output in my case notes in specific field textarea in the browser tab, but each time url and textarea ID is different.
(source html) textarea id="xx:caseViewForm:caseViewTabView:caseNotesInput"
so maybe I can send output to buffer and paste it using ctrl + v
the other thing when I tried to use xml or docx file as output, it creates them but I can't open it. (I'm receiving message corrupted file)
I am assuming that you dont want to write some sort of web server or web services. If your just double clicking on a file to see its output, rename the output textfile to .html
You can even print out html tags and format the text to make it look nicer.
PrintWriter output = new PrintWriter( ("C:\Documents and Settings\jszpakow\Desktop\ping.html"));
If you mean that you'd like to use a web browser as a text file viewer, they can do that by default. The URL format is file://$path, so in this case:
file://C:\Documents and Settings\jszpakow\Desktop\ping.txt
Renaming the file extension to .html would make your browser the default viewer, but you'll loose formatting on raw text.
However, if you mean you'd like to make the output available to other people on the web, you'd need a publicly-accessible web server to upload to. This means you'd either have to install and configure WAMP on your local machine, or get a web hosting account and FTP the file.
Whats wrong with notepad? You haven't used Notepad++, have you? Use it, it's will be far better than any browser.
I'm using a servlet to send a pdf stream to a browser.
There is a request that the pdf must open the print dialog when I show it to the user.
I was successful doing this using iText api. Something like this:
stamper.setPageAction(PdfWriter.PAGE_OPEN, new PdfAction(PdfAction.PRINTDIALOG), 1);
Now I do need to close the pdf file after print. I tried using pdfactions, but I'm can't get it. What I tried is:
writer.setAdditionalAction(PdfWriter.DID_PRINT, PdfAction.javaScript("app.execMenuItem('Close');", writer));
or
writer.setAdditionalAction(PdfWriter.DID_PRINT, PdfAction.javaScript("app.close();", writer));
I don't necessarily need to use pdfActions, but I don't see how to get it after user sent the pdf to printer.
Do you have any ideas?
There's a reason why app.execMenuItem('Close'); and app.close() don't work. These methods are designed to close the standalone version of Adobe Reader/Acrobat. I guess you're viewing the PDF in a browser, in which case you use Adobe Reader as a plug-in, Chrome's PDF viewer, pdf.js in Firefox, or any other PDF viewer.
Problem #1: you need to close the browser window from a PDF document. PDFs don't have the power to control your browser. Suppose they would: wouldn't that be a serious security issue?
Problem #2: you embed the PDF inside a HTML page (e.g. using an <object> tag) and establish a communication between the JavaScript in the PDF and the JavaScript in the HTML. I've described how to do this in my book, but: it won't work with all browsers on all OSs. For instance: Chrome's PDF viewer and Firefox's pdf.js will completely ignore your commands.
You are asking a solution using our iText library, but you're asking something that can't be done with any software.
I am using PD4ML to print a PDF file and It is working fine. Now the thing is I want show that file directly in acrobat with out save that file. In Local version I am using
Program.launch(getFilePath());
It is working fine but in web version I am unable to get that.
Can you please suggest me, Its very helpful.
Thanks,
Vara Kumar PJD
The web isn't like your desktop, so forget about doing things on the web the way you do them on the desktop without at least some effort.
Know that you don't read PDF files on the web using Acrobat without a browser plugin. Or some other reader like Foxit Reader.
My recommendation: forget about doing it this way. Either server your pdf as a file that can be downloaded, or read this SO post about embedding PDF in HTML.
I don't think this will be possible: "showing file outside browser in an application without user consent" because that is how browser are made for security reason. The best you can do is, as pointed in earlier post is by darioo, to show file in browser or prompt user to download/open.