Hi,
I am trying to generate pdf file from my Servlet and am getting the
following error. Please help as I have tried changing the code multiple
times but with no success :(
ExceptionConverter: java.io.IOException: The document has no pages.
The following is a snippet of my code in the servlet.
try {
// create simple doc and write to a ByteArrayOutputStream
//Document document = new Document();
Document document = new Document(PageSize.A4, 10, 10, 10, 40);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
PdfPTable table = new PdfPTable(2); //tab1 - with 2 col
table.setWidthPercentage(90f);
table.setSplitRows(true);
float[] widths = {0.2f, 0.3f, 0.25f, 0.25f};
PdfPTable nested1 = new PdfPTable(widths); //tab2 - with 4 cols
nested1.getDefaultCell().setBorderColor(new Color(255, 0, 0));
nested1.addCell("DHL Ref: SR / SO:");
nested1.addCell(srnumber + " / " + sonumber);
nested1.addCell("Cust Ref 1 / Ref 2:");
nested1.addCell("21408917 / 10705706");
nested1.addCell("Account Name:");
nested1.addCell("Sun Microsystems Bangalore");
nested1.addCell("WMS Order No:");
nested1.addCell("2756853");
nested1.addCell("Requestor Name:");
nested1.addCell("Reqfst name, Reqlst name");
nested1.addCell("Date And Time of Call:");
nested1.addCell("10/06/2005 14:17:43 +8");
nested1.addCell("Requestor Contact:");
nested1.addCell("+653956956");
nested1.addCell("Collection Date & Time:"); //configurable
nested1.addCell("10/06/2005 14:157:47 +8");
nested1.addCell("Service Level:");
nested1.addCell("Part Return");
nested1.addCell("Revised Time of Collection"); //configurable
nested1.addCell("-");
nested1.addCell("Agent Name:");
nested1.addCell("SIMON");
nested1.addCell("blank");
nested1.addCell("blank");
table.getDefaultCell().setColspan(2);
table.setHeaderRows(2);
table.addCell("Sun Microsystem Part Return SPC:SYD
ASL89012345"); //configurable
table.addCell(nested1);
document.add(table);
document.close();
// setting some response headers
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate,
post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
// setting the content type
response.setContentType("application/pdf");
// the contentlength is needed for MSIE!!!
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
} catch (Exception e2) {
System.out.println("Error in " + getClass().getName() + "\n" +
e2);
}
Thanks and Regards,
Julie
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions