Hi All,

I am using itextpdf-5.4.0.jar

I am getting the below exception on document.close();

com.itextpdf.text.exceptions.IllegalPdfSyntaxException: Unbalanced
save/restore state operators.
at
com.itextpdf.text.pdf.PdfContentByte.sanityCheck(PdfContentByte.java:3392)
at com.itextpdf.text.pdf.PdfContentByte.toPdf(PdfContentByte.java:279)
at com.itextpdf.text.pdf.PdfFormXObject.<init>(PdfFormXObject.java:88)
at com.itextpdf.text.pdf.PdfTemplate.getFormXObject(PdfTemplate.java:247)
at com.itextpdf.text.pdf.PdfWriter.addXFormsToBody(PdfWriter.java:1300)
at
com.itextpdf.text.pdf.PdfWriter.addSharedObjectsToBody(PdfWriter.java:1311)
at com.itextpdf.text.pdf.PdfWriter.close(PdfWriter.java:1216)
at com.itextpdf.text.pdf.PdfDocument.close(PdfDocument.java:810)
at com.itextpdf.text.Document.close(Document.java:416)


I have read the itext documentation about regarding unbalanced save state
and restore state and have *not *violated the below points

   - Unbalanced beginText() and endText() combinations
   - iText state operators outside a beginText() and endText() sequence
   - iText for which you forgot to set a font and size

A small code snippet from my code is given below

public void addSampleText() {
        if (!this.printPreview) {
            try {
                BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN,
BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                template.saveState();
                template.setRGBColorFill(this.stk_Red, this.stk_Green,
this.stk_Blue);
                PdfGState gstate = new PdfGState();
                gstate.setFillOpacity(0.7f);
                template.setGState(gstate);
                template.beginText();
                template.setFontAndSize(bf, sampleFontSize);
                template.showTextAligned(PdfContentByte.ALIGN_CENTER,
"Sample Label", sampleX, sampleY,

 (float)(Math.toDegrees(Math.atan2(this.stk_height, this.stk_width))));
                template.endText();
                template.restoreState();
            } catch (Exception exce) {
                exce.printStackTrace();
            }
        }
}

The template object is of type *PdfTemplate.*
*
*
I read through blogs and few have stated that this exception occurs iText 5
onwards.

Can any one suggest me why this exception has occurred?
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to