问题
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