Hi,

i want to print a pdf file silently via java code but the following
exception is thrown by document.close(): ExceptionConverter:
java.io.IOException: The document has no pages.

Opening the document is successful and the document also has a content.
I use itext-2.0.4.jar.

Here is my java code:
...
com.lowagie.text.Document document = new com.lowagie.text.Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(bytes); //bytes contains the document content

try {
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();
        writer.addJavaScript("this.print(false);", false); //for silently 
printing
        document.close();
} catch (Exception e) {
        e.printStackTrace();
}

final FacesContext context = FacesContext.getCurrentInstance();
final HttpServletResponse response = (HttpServletResponse)
context.getExternalContext().getResponse();
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
response.setHeader("Content-disposition", "attachment; filename=test.pdf");
response.getOutputStream().write(bytes);
response.getOutputStream().flush();

final StateManager stateManager =
context.getApplication().getStateManager();
stateManager.saveSerializedView(context);

// Finalize task.
context.responseComplete();
...

Thanks for helpful responses in advance,
Tom

-- 
View this message in context: 
http://www.nabble.com/PDF-print-problem-tf4533339.html#a12937317
Sent from the iText - General mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to