On first glance it looks like your PdfGraphics2D creates and disposes are
mismatched. You create one before the for loop. If there are more pages, you
dispose it and create a new one. This new one never gets disposed though. I
think this code below should fix it:
/**
* <code>createPdf</code> prints a set of pages into the PDF
* file.
*/
public void createPdf() {
// make an instance of a PdfGraphics Object for the document
DefaultFontMapper fm = new DefaultFontMapper();
java.awt.Graphics2D g = null;
// don't do anything if pageable is null
if (pageable != null) {
// read all fonts recognized be iText in system font path
fm.insertDirectory(sun.awt.font.NativeFontWrapper.getFontPath(true));
System.out.println("PdfJob.createPdf: started");
int pages = pageable.getNumberOfPages();
System.out.println("PdfJob.createPdf: pages to print: "+pages+"\n");
// set pageSize of first page before the document opens!!
float width = (float)pageable.getPageFormat(0).getPaper().getWidth();
float height = (float)pageable.getPageFormat(0).getPaper().getHeight();
theDocument.setPageSize(new Rectangle(width, height));
// g.setPageSize(pageable.getPageFormat(0));
theDocument.open();
for (int p = 0; p < pages ; ++p) {
//moved the create into the for loop
g = pdfWriter.getDirectContent().createGraphics(width, height, fm);
Printable thePage = pageable.getPrintable(p);
try {
// print!
thePage.print(g, pageable.getPageFormat(p), p);
System.out.println("PdfJob.createPdf: page " + p + " printed");
if (p < pages-1) {
// next page, please! on its proper PageSize
width =
(float)pageable.getPageFormat(p+1).getPaper().getWidth();
height =
(float)pageable.getPageFormat(p+1).getPaper().getHeight();
theDocument.setPageSize(new Rectangle(width, height));
} // end of if (p < pages-1)
theDocument.newPage();
} catch ( PrinterException e) {
e.printStackTrace();
}
catch(DocumentException de) {
de.printStackTrace();
}
g.dispose(); //dispose it here when you are done with it
} // end of for (int p = 0; p < pages; p++)
// write the document and clear all references
end(); // = theDocument.close()
} // end of if (pageable)
} // end createPdf
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions