Last g to be created is not used or disposed.
Best Regards,
Paulo Soares
> -----Original Message-----
> From: Erwin Achermann [SMTP:[EMAIL PROTECTED]]
> Sent: Monday, April 22, 2002 15:47
> To: [EMAIL PROTECTED]
> Subject: [iText-questions] PdfGraphics2D: unbalanced save/Restore
> Exception
>
> Hi iTexters,
>
> during the last week I was doing exactly a PdfGraphics class as you seem
> to have done. I was only implementing the features which we currently are
> using. Especially I was cheating with the FontMetrics. Now I realized this
> morning that you have done a more complete implementation in the
> PdfGraphics2D, reason enough for me to abandom my implementation and
> switch to the far more complete one of iText. But the problem I'm
> observing is show in the following code:
>
> /**
> * <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();
> g =
> pdfWriter.getDirectContent().createGraphics(width, height, fm);
>
> for (int p = 0; p < pages ; ++p) {
> 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();
>
> ////////////////////////////////////////////////////////
> // iText-Error!?
> // g.dispose(); // use of dispose
> leads to a
> // "unbalanced save/restore"
> exception not using
> // g.dispose() is producing
> erroneous PDF:
> // Acrobat Reader complains about
> unmatched
> // save/restore commands if the
> document consist
> // of Portrait and Landscape format.
> Acrobat Reader
> // show one empty additional page if
> the document
> // is only one page format
>
> /////////////////////////////////////////////////////////
> g =
> pdfWriter.getDirectContent().createGraphics(width, height, fm);
> } catch ( PrinterException e) {
> e.printStackTrace();
> }
> catch(DocumentException de) {
> de.printStackTrace();
> }
> } // 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
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions