Discussion:
[iText-questions] com.lowagie.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators
Yadhagiri Chilukuri
2012-04-06 05:13:21 UTC
Permalink
HI ,
I got this exception what are the situation came this exception :

com.lowagie.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators

give me sugetion how to debug itext code when the have face this type of exceptions

I searched In but not find suitable answer.


Thanks & Regards Yadagiri Ch
Product Development



[logo_new_emailsign.jpg]

Global R&D Center: Napier Healthcare Solutions (India).Ltd,
3rd & 4th floor, Capella Block, Ascendas, Plot No. 17,
Software Units Layout, Madhapur, Hyderabad - 500 081.
Tel : +91 40 33557777, Fax : +91 40 30461844
URL : www.napierhealthcare.com<http://www.napierhealthcare.com>



Disclaimer : This message (including attachment if any) is confidential and may be privileged. If you have received this message by mistake please notify the sender by return e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited. E-mail may contain viruses. Before opening attachments please check them for viruses and defects. While Napier HealthcareSolutions India Ltd. (Napier) has put in place checks to minimize the risks, Napier will not be responsible for any viruses or defects or any forwarded attachments emanating either from within Napier or outside.
1T3XT BVBA
2012-04-06 06:37:33 UTC
Permalink
Post by Yadhagiri Chilukuri
HI ,
com.lowagie.text.exceptions.IllegalPdfSyntaxException: Unbalanced
save/restore state operators
give me sugetion how to debug *itext* code when the have face this
type of exceptions
I searched In but not find suitable answer.
Search not further, just read the error message: you have unbalanced
save/restore state operators.
In other words, somewhere you have used the method saveState() without
using restoreState().
Or you have used restoreState() without using saveState().
Or maybe you have something like:

cb.saveState();
document.newPage();
cb.restoreState();

In older versions of iText, we allowed developers to write PDF syntax
any which way they want.
Unfortunately, when you give this power to developers who didn't read
and understand ISO-32000-1 (the standard you've probably read whilst
searching for a suitable answer), you end up with PDFs that are corrupt.
That's why we took away a little bit of that power. In order to make
iText more "fool-proof", we now throw an exception when a developer
doesn't respect the q/Q-rule.
glennr
2015-12-11 14:38:20 UTC
Permalink
I am getting the same error when I try to add multiple PdfPTable objects to a
document.

doc.add(table1);
doc.add(table2);
doc.close();

The thread mentioned doing a cb.saveState() and a cb.restoreState(). What
is "cb"?? Thanks.



--
View this message in context: http://itext.2136553.n4.nabble.com/com-lowagie-text-exceptions-IllegalPdfSyntaxException-Unbalanced-save-restore-state-operators-tp4536784p4660956.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-***@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
glennr
2015-12-11 14:40:27 UTC
Permalink
I am getting the same error when I try to add multiple PdfPTable objects to a
document.

doc.add(table1);
doc.add(table2);
doc.close();

The thread mentioned doing a cb.saveState() and a cb.restoreState(). What
is "cb"?? Thanks.



--
View this message in context: http://itext.2136553.n4.nabble.com/com-lowagie-text-exceptions-IllegalPdfSyntaxException-Unbalanced-save-restore-state-operators-tp4536784p4660957.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-***@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
i***@1t3xt.info
2015-12-12 11:57:24 UTC
Permalink
You are using a version that dates from at least July 2009.
You are experiencing a bug that has been fixed many years ago.
Please upgrade to a recent version of iText if you want to solve your
problem.
Post by glennr
I am getting the same error when I try to add multiple PdfPTable objects to a
document.
doc.add(table1);
doc.add(table2);
doc.close();
The thread mentioned doing a cb.saveState() and a cb.restoreState().
What
Post by glennr
is "cb"?? Thanks.
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-***@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
glennr
2015-12-14 15:02:55 UTC
Permalink
I'm not using an old version.  I downloaded version 5.5.8 last Thursday to upgrade from a really old version I was using.  When I downloaded new version 5.5.8 is when my problem started.  Please advise.  Thanks.
From: iText mailing list [via iText] <ml-node+***@n4.nabble.com>
To: glennr <***@yahoo.com>
Sent: Saturday, December 12, 2015 5:09 AM
Subject: Re: com.lowagie.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators

You are using a version that dates from at least July 2009.
You are experiencing a bug that has been fixed many years ago.
Please upgrade to a recent version of iText if you want to solve your
problem.
Post by glennr
I am getting the same error when I try to add multiple PdfPTable objects to a
document.
        doc.add(table1);
        doc.add(table2);
        doc.close();
The thread mentioned doing a cb.saveState() and a cb.restoreState().
What
Post by glennr
is "cb"??  Thanks.
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[hidden email]
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


If you reply to this email, your message will be added to the discussion below: http://itext.2136553.n4.nabble.com/com-lowagie-text-exceptions-IllegalPdfSyntaxException-Unbalanced-save-restore-state-operators-tp4536784p4660958.html To unsubscribe from com.lowagie.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators, click here.
NAML





--
View this message in context: http://itext.2136553.n4.nabble.com/com-lowagie-text-exceptions-IllegalPdfSyntaxException-Unbalanced-save-restore-state-operators-tp4536784p4660959.html
Sent from the iText mailing list archive at Nabble.com.
mkl
2015-12-14 15:41:25 UTC
Permalink
glennr,
I'm not using an old version.  I downloaded version 5.5.8 last Thursday to
upgrade from a really old version I was using.  When I downloaded new
version 5.5.8 is when my problem started.
I am getting the same error when I try to add multiple PdfPTable objects
to a document.
in response to a message about a
com.lowagie.text.exceptions.IllegalPdfSyntaxException - and if you indeed
got a com.LOWAGIE.... exception, you ARE using a version that dates from at
least July 2009.

If you merely did not read carefully what you responded to and actually got
a com.ITEXTPDF.... exception, please share a runnable example

Regards, Michael



--
View this message in context: http://itext.2136553.n4.nabble.com/com-lowagie-text-exceptions-IllegalPdfSyntaxException-Unbalanced-save-restore-state-operators-tp4536784p4660962.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-***@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
glennr
2015-12-14 16:08:07 UTC
Permalink
Thanks for your quick response.

See attached example files with my report. ReportManager is the main driver
class that sets variables and makes the call to generate the warrant report.
This is a prototype so please excuse all the commented code of different
things I am trying.

ReportManager.java
<http://itext.2136553.n4.nabble.com/file/n4660963/ReportManager.java>
WarrantRpt.java
<http://itext.2136553.n4.nabble.com/file/n4660963/WarrantRpt.java>
ReportPageEvent.java
<http://itext.2136553.n4.nabble.com/file/n4660963/ReportPageEvent.java>



--
View this message in context: http://itext.2136553.n4.nabble.com/com-lowagie-text-exceptions-IllegalPdfSyntaxException-Unbalanced-save-restore-state-operators-tp4536784p4660963.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-***@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
mkl
2015-12-14 16:45:05 UTC
Permalink
Post by glennr
See attached example files with my report. ReportManager is the main
driver class that sets variables and makes the call to generate the
warrant report. This is a prototype so please excuse all the commented
code of different things I am trying.
ReportManager.java
<http://itext.2136553.n4.nabble.com/file/n4660963/ReportManager.java>
WarrantRpt.java
<http://itext.2136553.n4.nabble.com/file/n4660963/WarrantRpt.java>
ReportPageEvent.java
<http://itext.2136553.n4.nabble.com/file/n4660963/ReportPageEvent.java>
Unfortunately I cannot run that code, I cannot access your database and I do
not have all the referenced classes.

Please share a Short, Self Contained, Compilable Example
<http://sscce.org/> .

Regards, Michael



--
View this message in context: http://itext.2136553.n4.nabble.com/com-lowagie-text-exceptions-IllegalPdfSyntaxException-Unbalanced-save-restore-state-operators-tp4536784p4660964.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-***@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
Glenn R
2015-12-14 15:29:20 UTC
Permalink
This is the exception stack trace I get if it helps.----------------------------
com.itextpdf.text.DocumentException: com.itextpdf.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators. at com.itextpdf.text.pdf.PdfDocument.add(PdfDocument.java:818) at com.itextpdf.text.Document.add(Document.java:278) at rpt.WarrantRpt.createReport(WarrantRpt.java:1656) at rpt.ReportManager.writeReport(ReportManager.java:286) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at wcon.ConnectionServlet.process(ConnectionServlet.java:615) at wcon.ConnectionServlet.doPost(ConnectionServlet.java:368) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:824) at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:330) at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:830) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:285) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:126) at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192) at java.lang.Thread.run(Thread.java:619)Caused by: com.itextpdf.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators. at com.itextpdf.text.pdf.PdfContentByte.sanityCheck(PdfContentByte.java:4155) at com.itextpdf.text.pdf.PdfContentByte.reset(PdfContentByte.java:1794) at com.itextpdf.text.pdf.PdfContentByte.reset(PdfContentByte.java:1782) at com.itextpdf.text.pdf.PdfWriter.resetContent(PdfWriter.java:747) at com.itextpdf.text.pdf.PdfDocument.endPage(PdfDocument.java:1058) at com.itextpdf.text.pdf.PdfDocument.newPage(PdfDocument.java:939) at com.itextpdf.text.pdf.PdfDocument.addPTable(PdfDocument.java:2729) at com.itextpdf.text.pdf.PdfDocument.add(PdfDocument.java:756) ... 18 more
From: "***@1t3xt.info" <***@1t3xt.info>
To: Post all your questions about iText here <itext-***@lists.sourceforge.net>
Sent: Saturday, December 12, 2015 4:57 AM
Subject: Re: [iText-questions] com.lowagie.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators

You are using a version that dates from at least July 2009.
You are experiencing a bug that has been fixed many years ago.
Please upgrade to a recent version of iText if you want to solve your
problem.
Post by glennr
I am getting the same error when I try to add multiple PdfPTable objects to a
document.
        doc.add(table1);
        doc.add(table2);
        doc.close();
The thread mentioned doing a cb.saveState() and a cb.restoreState().
What
Post by glennr
is "cb"??  Thanks.
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-***@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
glennr
2015-12-14 15:15:09 UTC
Permalink
This is the stack trace I get if it helps.  Thanks
--------------------------------com.itextpdf.text.DocumentException: com.itextpdf.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators. at com.itextpdf.text.pdf.PdfDocument.add(PdfDocument.java:818) at com.itextpdf.text.Document.add(Document.java:278) at rpt.WarrantRpt.createReport(WarrantRpt.java:1656) at rpt.ReportManager.writeReport(ReportManager.java:286) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at wcon.ConnectionServlet.process(ConnectionServlet.java:615) at wcon.ConnectionServlet.doPost(ConnectionServlet.java:368) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:824) at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:330) at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:830) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:285) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:126) at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192) at java.lang.Thread.run(Thread.java:619)Caused by: com.itextpdf.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators. at com.itextpdf.text.pdf.PdfContentByte.sanityCheck(PdfContentByte.java:4155) at com.itextpdf.text.pdf.PdfContentByte.reset(PdfContentByte.java:1794) at com.itextpdf.text.pdf.PdfContentByte.reset(PdfContentByte.java:1782) at com.itextpdf.text.pdf.PdfWriter.resetContent(PdfWriter.java:747) at com.itextpdf.text.pdf.PdfDocument.endPage(PdfDocument.java:1058) at com.itextpdf.text.pdf.PdfDocument.newPage(PdfDocument.java:939) at com.itextpdf.text.pdf.PdfDocument.addPTable(PdfDocument.java:2729) at com.itextpdf.text.pdf.PdfDocument.add(PdfDocument.java:756) ... 18 more
From: iText mailing list [via iText] <ml-node+***@n4.nabble.com>
To: glennr <***@yahoo.com>
Sent: Saturday, December 12, 2015 5:09 AM
Subject: Re: com.lowagie.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators

You are using a version that dates from at least July 2009.
You are experiencing a bug that has been fixed many years ago.
Please upgrade to a recent version of iText if you want to solve your
problem.
Post by glennr
I am getting the same error when I try to add multiple PdfPTable objects to a
document.
        doc.add(table1);
        doc.add(table2);
        doc.close();
The thread mentioned doing a cb.saveState() and a cb.restoreState().
What
Post by glennr
is "cb"??  Thanks.
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[hidden email]
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


If you reply to this email, your message will be added to the discussion below: http://itext.2136553.n4.nabble.com/com-lowagie-text-exceptions-IllegalPdfSyntaxException-Unbalanced-save-restore-state-operators-tp4536784p4660958.html To unsubscribe from com.lowagie.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators, click here.
NAML





--
View this message in context: http://itext.2136553.n4.nabble.com/com-lowagie-text-exceptions-IllegalPdfSyntaxException-Unbalanced-save-restore-state-operators-tp4536784p4660960.html
Sent from the iText mailing list archive at Nabble.com.
glennr
2015-12-11 14:30:02 UTC
Permalink
I am getting the same error when I try to add multiple PdfPTable objects to a
document.

doc.add(table1);
doc.add(table2);
doc.close();

The thread mentioned doing a cb.saveState() and a cb.restoreState(). What
is "cb"?? Thanks.



--
View this message in context: http://itext.2136553.n4.nabble.com/com-lowagie-text-exceptions-IllegalPdfSyntaxException-Unbalanced-save-restore-state-operators-tp4536784p4660955.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-***@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
Loading...