Harsha Kaundinya
2013-05-28 13:43:07 UTC
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?
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?