How to view pdf file in java/jsp?

Hello Everybody,
Any one help me how to view pdf file in jsp using java application.
I have pdf file c:\app.pdf.
How can i display the pdf file.
Please help me.................
Thanks

Hello,
You can use the below code, but i am not sure how far is this a startard way of doing it.
# <%
# ServletOutputStream servletOutputStream = response.getOutputStream();
# File reportFile = new File("C:\\Tomcat 5.0\\webapps\\TestApp\\myfile.pdf");
# FileInputStream fis = new FileInputStream(reportFile);
# byte[] bytes= new byte[128000];
# int count=fis.read(bytes);
# try
# response.setContentType("application/pdf");
# response.setContentLength(bytes.length);
# servletOutputStream.write(bytes, 0, bytes.length);
# servletOutputStream.flush();
# servletOutputStream.close();
# }catch(Exception e){}

Similar Messages

  • How to print PDF files using java print API

    Hi,
    I was goign throw lot of discusion and reading lot of forums related to print pdf files using java api. but nothing seems to be working for me. Can any one tell me how to print pdf files using java api.
    Thanks in advance

    Mike,
    Can't seem to get hold of the example described in your reply below. If you could let us have the URL to get then it would be great.
    My GUI application creates a pdf document which I need to print. I want to achieve this using the standard Java class PrinterJob (no 3rd party APIs I'm afraid, commercial restraints etc ..). I had a stab at it using the following code. When executed I get the pretty printer dialog then when I click ok to print, nothing happens!
    boolean showPrintDialog=true;
    PrinterJob printJob = PrinterJob.getPrinterJob ();
    printJob.setJobName ("Contract.pdf");
    try {
    if (showPrintDialog) {
    if (printJob.printDialog()) {
    printJob.print();
    else
    printJob.print ();
    } catch (Exception PrintException) {
                   PrintException.printStackTrace();
    Thank you and a happy new year.
    Cheers,
    Chris

  • How to read pdf files using java.io package classes

    Dear All,
    I have a certain requirement that i should read and write PDF files at runtime. With normal java file IO reading is not working. Can any one suggest me how to proceed probably with sample code block
    Thanks in advance.

    hi I also have the pbm. to read pdf file using JAVA
    can any body help meWhy is it so difficult to read the thread you posted in? They say: java.io is pointless, use iText. So why don't you?
    or also I want to read a binary encoded data into
    ascii,
    can anybody give me a hint how to do it.Depends on what you mean with "binary encoding". ASCII's binary encoding, too, basically.

  • How to view PDF files like a flipping magazine?

    Hi, I am new here. I didn't know if it is the optimum catagory for my question, I hope you guys will help me.
    In brief, I want to view PDF files like a flipping magazine. You know, just the same flipping effect that ibook did on ios. Adobe reader is the only choice to browse PDF on computer for me. It's kind of bothering and annoying now.
    So, any ideas for that? Plus, my computer runs on win7 64bit.

    This is also a good site:  http://www.issuu.com/  You can sign up and use it for free or you can upgrade(for a price) to make custom changes (like background color, button color, etc.)  You can also embed the html code into your website if you would like someone to view it there.  Good luck!

  • HOW TO VIEW .PDF FILES IN ITOUCH4 .

    I DO NOT HAVE INTERNET CONNECTION . CAN ANYONE HELP ME IN VIEWING .PDF FILES LOCALLY WITHOUT INTERNET CONNECTION.DO ITOUCH4 HAVE BUILT IN FEATURE TO VIEW .PDF FILES.

    Hello pvoona,
    And welcome to Apple Discussions!
    DO ITOUCH4 HAVE BUILT IN FEATURE TO VIEW .PDF FILES.
    No it does not. You'll need the help of an application from the App store in order to do this. You can also view PDFs on the web via Safari.
    And for future reference, please do not type in all caps. It gives the impression that you are yelling.
    B-rock

  • How to display pdf file with java code?

    Hi All,
    i have a jsp pagein that page if i click one icon then my backing bean method will call and that method will create pdf document and write some the content in that file and now i want to display that generated pdf document.
    it should look like you have pressed one icon and it displayed pdf file to you to view.
    java code below:
    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext ec = fc.getExternalContext();
    HttpServletResponse resp = (HttpServletResponse) ec.getResponse();
    resp.setHeader("Content-Disposition", "filename=\"" + temppdfFile);
    resp.encodeRedirectURL(temppdfFile.getAbsolutePath());
    resp.setContentType("application/pdf");
    ServletOutputStream out = resp.getOutputStream();
    ServletUtils.returnFile(temppdfFile, out);
    out.flush();
    and above temppdfFile is my generated pdf file.
    when i am executing this code, it was opening dialog box for save and cancel for the file, but the name of the file it was showing me the "jsp file name" with no file extention (in wich jsp file i am calling my backing bean method) and type is "Unknown File type" and from is "local host"
    it was not showing me open option so i am saving that file then that file saved as a pdffile with tha name of my jsp file and there is nothing in that file(i.e. empty file).
    what is the solution for this. there is any wrong in my code.
    Please suggest me.
    Thanks in advance
    Indira

    public Object buildBarCodes() throws Exception
    File bulkBarcodes = null;
    String tempPDFFile = this.makeTempDir();
    File tempDir = new File("BulkPDF_Files_Print");
    if(!tempDir.exists())
    tempDir.mkdir();
    bulkBarcodes = File.createTempFile
    (tempPDFFile, ".pdf", tempDir);
    //bulkBarcodes = new File(tempDir, tempPDFFile+"BulkBarcode"+"."+"pdf");
    if(!bulkBarcodes.exists())
    bulkBarcodes.createNewFile();
    Document document = new Document();
    FileOutputStream combinedOutput = new FileOutputStream(bulkBarcodes);
    PdfWriter.getInstance(document, combinedOutput);
    document.open();
    document.add(new Paragraph("\n"));
    document.add(new Paragraph("\n"));
    Image image = Image.getInstance(bc.generateBarcodeBytes(bc.getBarcode()));
    document.add(image);
    combinedOutput.flush();
    document.close();
    combinedOutput.close();
    FacesContext facesc = FacesContext.getCurrentInstance();
    ExternalContext ec = facesc.getExternalContext();
    HttpServletResponse resp = (HttpServletResponse) ec.getResponse();
    resp.setHeader("Content-Disposition", "inline: BulkBarcodes.pdf");
    resp.encodeRedirectURL(bulkBarcodes.getAbsolutePath());
    resp.setContentType("application/pdf");
    resp.setBufferSize(10000000);
    ServletOutputStream out = resp.getOutputStream();
    ServletUtils.returnFile(bulkBarcodes, out);
    out.flush();
    return "success";
    This is my action method which will call when ever i press a button in my jsp page.
    This method will create the barcode for the given barcode number and write that barcode image in pdf file
    (i saw that pdf file which i have created through my above method, This PDF file opening when i was opening manually and the data init that is also correct means successfully it writes the mage of that barcode)
    This method taking the jsp file to open because as earlier i said it was trying to open unknown file type document and i saved that file and opended with editplus and that was the jsp file in which file i am calling my action method I mean to say it was not taking the pdf file which i have created above it was taking the jsp file

  • How to print PDF file from java application?

    Hi,
    I have a java application that needs to print an PDF files. Could any one provide me links to tutorial/sample codes for doing this?

    http://onesearch.sun.com/search/onesearch/index.jsp?qt=print+pdf+files&subCat=&site=dev&qp=&chooseCat=javaall&col=developer-forums

  • How to view pdf files inside firefox?

    I spent hours on this. pdf.js sucks ass. Neither foxit nor adobe reader works. I have been using firefox since 2.0.0.20. I will have to quit if I can't view the pdf files inside my browser! The worst thing that has ever happened to firefox is the pdf.js shit. It is slow as shit and useless like shit. Just let pdf files be handled by the pdf program.

    hello, please refer to [[How to disable the built-in PDF viewer and use another viewer]]

  • How to view PDF files strored in a BLOB column

    Hi all,
    I want to display a PDF file, stored in a BLOB column, in a form or through a JavaBean.
    But the problem is more complicated then that. I do not want to retrieve the PDF file in the application server that show it through a browser.
    Actually, I do not want users to get the entire file, I just want them to see it or print it.
    I want, in fact, to display a "stream" of bytes through Oracle Forms. Not a file.
    This one, sounded to be a good solution, but actually not. When the file was too big (multiple pages), the application was blocked until the entire file was loaded. And when you try to print it, it wasn't printed right. The advantage of this solution is that it is open-source so we can add methods to connect to the DB, retrieve the content of the BLOB column and displays it without downloading the file.
    Here is a good solution. Really good, files are loaded quickly, the rendering is really good and the file is printed perfectly (as it was printed from Adobe Acrobat). The disadvantage of this solution is that it is not open-source and is really expansive.
    As you can see, both solutions uses PJC.
    So any help, any idea to solve my problem will be highly appreciated.
    Thanks to all of you,
    Amine
    PS : I am using F&R 11gR2

    Not entirely. At least we came to the conclusion it doesn't make (much) sense to block the save option of PDFs if you want to allow printing them
    Anyway; there is of course another possibilty: you could always write your own java bean PDF reader; there are plenty of java PDF libraries available:
    Open Source PDF Libraries in Java
    The easiest way would be to choose one which can open a PDF from a URL and render it; I would retrieve the image via mod_plsql using WPG_DOCLOAD and simply use the PDF library to render the PDF. No tempfiles anyway, and if you don't implement it there is also no save button.
    cheers

  • How to view PDF files in Safari

    Hi,
    I can't view PDFs in Safari since updating to 5.1.  I just get the annoying dark-grey screen
    I don't have Adobe Reader/Pro installed, I don't have the internet plugin, I have tried running the phrase in Terminal that is supposed to tell Safari to open PDFs not get another program to (cut and paste into terminal as is from various other threads) and I have tried downloading the file form this address: http://www.macupdate.com/info.php/id/22361/safari-display-or-download-pdf-files (incidentally, I can't download it because Safari tries to open the .dmg file in a new tab, but that doesn't work, nor does OPT-click -> Download linked file allow me to download it).
    I've been to the Genius Bar at that local Apple store and the tech couldn't help - even though she looked at the problem for about 30 mins.
    Does anyone know of any other possible fixes for this incredicbly annoying problem?
    Cheers
    Sean..

    Please enable guest logins and log in as Guest. Test. Same problem?
    Mac OS X 10.6 Help: Creating a guest user account

  • How to view PDF files in Safari 5.1?

    Every time I try to view a PDF file in Safari 5.1.1 (double clicking or using the contextual menu)i, it downloads the file instead. Is there a fix for this?
    Adobe tells me that their plugin will not work with Safari 5.1 (with Lion or Snow Leopard) and suggests that I revert to Safari 5.0/Leopard.
    A.

    Go to /Library/Internet Plug-Ins.
    Move the PDF Browser Plug-In to the Trash.
    Restart your Mac. Try viewing a PDF in Safari.
    Known Issues | Adobe products on Mac OS 10.7 Lion

  • How to view pdf files without downloading them on firefox for android

    I use an Electronic Medical Record program using Firefox for android on a a Samsung Galaxy Pro 12.2 tablet. I need to view patient pdf files on the tablet. So far, the only way I have been able to accomplish this is to download the file first. It would be more efficient if I could just view the pdf file on the Galaxy tablet without having to download it. Is it possible to do this with Firefox for android? Thanks.

    Not in any reliable manner. There is PDF.js but it has not been optimized for Firefox for Android. https://github.com/mozilla/pdf.js/#firefox

  • How to view pdf files in xperia mini pro

    I have downdoaded a Sony ericsson mobile manual in pdf format. I tried to open it in my mobile by using office suit but its not opening. How to solve this problem?

    Well, like mentioned above, Adeobe reader is a good choice for pdf readering. But if you need a comprehensive pdf viewer, which can offers more funtions rather than only pdf reading option, then you can try a certain pdf windows viewer. I seldomly use such pdf reader, but they are great indeed. Because you can use it to view and realize some basic pdf processings.

  • How to upload pdf file in iphone and how to view

    how to upload and how to view pdf file in iphone 5s

    Hey saif.antri,
    You can view PDFs and more using iBooks on your iPhone:
    iBooks: Viewing, syncing, saving, and printing PDFs on iPhone, iPad, and iPod touch
    http://support.apple.com/kb/HT4227
    Have a great day,
    Delgadoh

  • How to display pdf file in windows phone 8 silver light application?

    Hi,
    I am developing windows phone 8 silver light application . For my app I want to display pdf files . Is there any default controls to display pdf files ?
    I don't want to display using launchers , I want to display with in the app.
    any help,
    Thanks..
    Suresh.M

    Probably this should give you a fair idea : How to view PDF file inside an Windows Phone application?
    http://developer.nokia.com/community/wiki/Using_Crypto%2B%2B_library_with_Windows_Phone_8

Maybe you are looking for

  • Error when adding a ZFS Storage in the Desktop Provider configuration in Oracle VDI

    Hello, When I tried to add a Desktop Provider in Oracle VDI I received an error in the 4 option after the Certificate verification in Specify Storages. Here's the log: LA M▒<81>S FINA: thr#20197:"Thread-46528" Congestion Retry 1 for root at 10.10.10.

  • CMDKEY script no password prompt

    Here is a script I'm using to store the credentials for server shares: @echo off cd C:\Windows\System32 cmdkey /add:PrintServer /user:demo\%username% /password:%pw% Now, if I'm running the command from a prompt live, then it works just great without

  • One step approval workflow

    Hi All, I have added a step in one step approval workflow to check shop on behalf. When a person shop's on behalf of a manager, and 1 step approval is triggered, i want the approver to be the manager. But what is happening is that Manager's Manager i

  • Live Migration to Best possible node

    Hi, I have a 20 node cluster with virtual machine role. I would like know equivalent power shell command for migrating VMs to best possible node. When I right click on VM from cluster manager, I see below option for Live migration to Best possible no

  • Can I update my Ipod touch first generation to iOS 4.3?

    I've had my 16 GB ipod touch first generation (With built in WiFi) since it was the newest model out. I would like to update to a newer model but money is tight. I was hoping someone could tell me if, and how, I can update my ipod to the latest softw