display pdf in browser using itext

余生颓废 提交于 2020-01-17 15:41:07

问题


i have modify a pdf with itext using pdfstamper. my application now create and save a new pdf file. i want to dipslay the pdf directly in the browser. Here my actual code

public static void test07(){
    try{
    PdfReader reader = new PdfReader("c:\\temp\\file.pdf");
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("c:\\temp\\new.pdf"));
        AcroFields form = stamper.getAcroFields();

        //fill the fields

        stamper.close();
        reader.close();
    } catch (Exception e){
        e.printStackTrace();
    }

}

The question is: How should I modify this code and the servlet to display the pdf file in the browser? I have already tried with ByteArrayOutputStream and response.getOutputStream but nothing.


回答1:


You're in luck! The book iText in Action contains a chapter that describes how to do exactly what you need. It's fairly straightforward: set the right headers on your response, and stream to the servlet's output stream.

Here's the link: http://itextpdf.com/examples/iia.php?id=173



来源:https://stackoverflow.com/questions/24202167/display-pdf-in-browser-using-itext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!