Quantcast

Error: Unbalanced begin/end text operators since iText 5

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Error: Unbalanced begin/end text operators since iText 5

alrts
When I wanted to use chunk.SetCharacterSpacing(), I realized that it was about time to update my 4 year old iTextSharp library. Many classes disappeared and I had to update my code. However I'm still stuck with an error message which did not show up before, namely

Error: Unbalanced begin/end text operators

The code in question looks like this:

document = new Document();
writer = PdfWriter.GetInstance(document, pdfFile);
document.Open();
cb = writer.DirectContent;
bf = BaseFont.CreateFont(fontfile, BaseFont.WINANSI, true);
font = new Font(bf, size, style);
chunk = new Chunk(contentString, font);
phrase = new Phrase(chunk);
ct = new ColumnText(cb);
ct.SetSimpleColumn(a, b, c, d, e, f);
ct.AddText(phrase);
ct.Go();
document.NewPage();

I'm getting the error after the last statment. I also tried with setting cb.BeginText() and cb.EndText() at several places but this changed nothing. As I said, this code worked with iTextSharp release 3.1.1.

Any help is highly appreciated!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end text operators sinceiText 5

Paulo Soares-3
You must have something else going on. Please post the complete code so that the problem can be reproduced.
 
Paulo
----- Original Message -----
Sent: Monday, August 30, 2010 8:52 AM
Subject: [iText-questions] Error: Unbalanced begin/end text operators sinceiText 5


When I wanted to use chunk.SetCharacterSpacing(), I realized that it was
about time to update my 4 year old iTextSharp library. Many classes
disappeared and I had to update my code. However I'm still stuck with an
error message which did not show up before, namely

Error: Unbalanced begin/end text operators

The code in question looks like this:

document = new Document();
writer = PdfWriter.GetInstance(document, pdfFile);
document.Open();
cb = writer.DirectContent;
bf = BaseFont.CreateFont(fontfile, BaseFont.WINANSI, true);
font = new Font(bf, size, style);
chunk = new Chunk(contentString, font);
phrase = new Phrase(chunk);
ct = new ColumnText(cb);
ct.SetSimpleColumn(a, b, c, d, e, f);
ct.AddText(phrase);
ct.Go();
document.NewPage();

I'm getting the error after the last statment. I also tried with setting
cb.BeginText() and cb.EndText() at several places but this changed nothing.
As I said, this code worked with iTextSharp release 3.1.1.

Any help is highly appreciated!
--
View this message in context: http://itext-general.2136553.n4.nabble.com/Error-Unbalanced-begin-end-text-operators-since-iText-5-tp2399694p2399694.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end text operators sinceiText 5

alrts
Paolo,

the code is huge and difficult to supply. In the meantime, I could generate the same error at the ContentByte level. Here it is obvious that something strange is going on:

document = new Document();
document.Open();
writer = PdfWriter.GetInstance(document, pdfFile);
cb = writer.DirectContent;
cb.BeginText();
bf = BaseFont.CreateFont(fontfile, BaseFont.WINANSI, true);
cb.SetFontAndSize(bf, fontSize);
cb.SetTextMatrix(a, b, c, d, e, f);  //values for a,b,c,d,e,f : 45, 450, 550, 479, 0, 1
cb.ShowText(contentString);  //value for contentString = "Astrological Portrait"
cb.EndText();
document.NewPage();

The font I use is Century Gothic True Type (GOTHIC.ttf), the contentString is two words only. I switched back to 3.1.1 and get no error. I compared the two objects cb and document and they seem the same for both 3.1.1 and 5.0.4 versions. It is strange but in both versions I cannot actually find the cb content within the document object.  Anyway I'm getting the same error when using iTextSharp 5.0.4:

Error: Unbalanced begin/end text operators

(By the way, when I use this code instead of the ColumnText code above with 3.1.1 I'm getting huge letters!)

Please help!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end text operators sinceiText 5

Leonard Rosenthol-3
The ONLY THING between BT and ET should be the matrix and the text - move the font calls outside the BT/ET block

-----Original Message-----
From: alrts [mailto:[hidden email]]
Sent: Monday, August 30, 2010 8:16 AM
To: [hidden email]
Subject: Re: [iText-questions] Error: Unbalanced begin/end text operators sinceiText 5


Paolo,

the code is huge and difficult to supply. In the meantime, I could generate
the same error at the ContentByte level. Here it is obvious that something
strange is going on:

document = new Document();
document.Open();
writer = PdfWriter.GetInstance(document, pdfFile);
cb = writer.DirectContent;
cb.BeginText();
bf = BaseFont.CreateFont(fontfile, BaseFont.WINANSI, true);
cb.SetFontAndSize(bf, fontSize);
cb.SetTextMatrix(a, b, c, d, e, f);  //values for a,b,c,d,e,f : 45, 450,
550, 479, 0, 1
cb.ShowText(contentString);  //value for contentString = "Astrological
Portrait"
cb.EndText();
document.NewPage();

The font I use is Century Gothic True Type (GOTHIC.ttf), the contentString
is two words only. I switched back to 3.1.1 and get no error. I compared the
two objects cb and document and they seem the same for both 3.1.1 and 5.0.4
versions. It is strange but in both versions I cannot actually find the cb
content within the document object.  Anyway I'm getting the same error when
using iTextSharp 5.0.4:

Error: Unbalanced begin/end text operators

(By the way, when I use this code instead of the ColumnText code above with
3.1.1 I'm getting huge letters!)

Please help!

--
View this message in context: http://itext-general.2136553.n4.nabble.com/Error-Unbalanced-begin-end-text-operators-since-iText-5-tp2399694p2400002.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end text operators sinceiText 5

alrts
I'm afraid this is not the solution. The error still persists.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end text operators sinceiText 5

iText Info
In reply to this post by alrts
alrts wrote:
> Paolo,
>
> the code is huge and difficult to supply. In the meantime, I could generate
> the same error at the ContentByte level. Here it is obvious that something
> strange is going on:
>
> document = new Document();
> document.Open();
> writer = PdfWriter.GetInstance(document, pdfFile);

It would be very strange if this worked.
You're opening the document before creating the writer.
I don't think this is your code sample.

> I switched back to 3.1.1 and get no error.

Maybe not, but your PDF has an error.
The "Unbalanced begin/end text" exception makes sure
you don't create PDFs with that error.

> Please help!

You need an EndText() for every BeginText(), and vice-versa.
Somewhere in your code, you have a BeginText() but EndText() is
never reached. Or you have an EndText(), but there wasn't a
BeginText() to begin with.

You CAN NOT reproduce that error with your code snippet.
Try this example:
http://kuujinbo.info/iTextInAction2Ed/index.aspx?ch_key=Chapter03&cl_key=FestivalOpening
Does it work?


------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end text operators sinceiText 5

alrts
Yes sure, Document.Open() comes after the writer just as in my first example.

And yes, of course, each BeginText() must match with an EndText(). This is the case.

Just keep in mind that this code worked perfectly with iTextSharp 3.1.1 for years.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end text operators sinceiText 5

alrts
... and moreover, if you have experience with ColumnText(), and you look at my very first example, the one which actually was running for years, it does not contain any BeginText() and EndText() on the level of ColumnText(). To my knowledge, this is valid iTextSharp coding, and runs flawless on 3.1.1, and still produces this mismach error. Very strange indeed.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end text operators sinceiText 5

iText Info
alrts wrote:
> ... and moreover, if you have experience with ColumnText(), and you look at
> my very first example, the one which actually was running for years, it does
> not contain any BeginText() and EndText() on the level of ColumnText(). To
> my knowledge, this is valid iTextSharp coding, and runs flawless on 3.1.1,
> and still produces this mismach error. Very strange indeed.

We can't fix what we can't reproduce.
Moreover: your code may have been executed without error in the past,
but the resulting PDF probably had an error (that was ignored by Adobe
Reader).

Provide a complete standalone example that reproduces the problem.
Your code snippet was not a standalone example; you didn't copy/paste
it from something that worked because you had the Document.Open() at
the wrong place.

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end text operatorssinceiText 5

Paulo Soares-3
In reply to this post by alrts
Here's what you have to do if you want this to advance anywhere:
 
- Provide us with a small but complete code sample exhibiting the problem. Just a class with a Main(), without any dependencies, nothing else.
 
Paulo
----- Original Message -----
Sent: Monday, August 30, 2010 4:02 PM
Subject: Re: [iText-questions] Error: Unbalanced begin/end text operatorssinceiText 5


Yes sure, Document.Open() comes after the writer just as in my first example.

And yes, of course, each BeginText() must match with an EndText(). This is
the case.

Just keep in mind that this code worked perfectly with iTextSharp 3.1.1 for
years.

--
View this message in context: http://itext-general.2136553.n4.nabble.com/Error-Unbalanced-begin-end-text-operators-since-iText-5-tp2399694p2400266.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end text operators sinceiText 5

alrts
In reply to this post by Paulo Soares-3
Referring back to my first example with ColumnText(), the internal buffer of the ColumnText ct reads just before the document is closed:

Canvas = {BT
1 0 0 1 163.67 479.06 Tm
/F1 26 Tf
(Astrologisches Porträt)Tj
ET
}

This looks pretty much ok, BT being short for BeginText(), then comes the SetSimpleColumn(...), followed by the phrase (preceded by the chunk's font) and ET for endText(). But, upon CloseDocument() the

Unbalanced begin/end text operators

error appears. Can anybody see a problem here ?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end text operatorssinceiText 5

Paulo Soares-3

The only problem I can see here is that you are still ignoring the request for a simple, complete, standalone example. I'm ok you that, it's your problem, not mine.
 
Paulo
----- Original Message -----
Sent: Monday, August 30, 2010 4:59 PM
Subject: Re: [iText-questions] Error: Unbalanced begin/end text operatorssinceiText 5


Referring back to my first example with ColumnText(), the internal buffer of
the ColumnText ct reads just before the document is closed:

Canvas = {BT
1 0 0 1 163.67 479.06 Tm
/F1 26 Tf
(Astrologisches Porträt)Tj
ET
}

This looks pretty much ok, BT being short for BeginText(), then comes the
SetSimpleColumn(...), followed by the phrase (preceded by the chunk's font)
and ET for endText(). But, upon CloseDocument() the

Unbalanced begin/end text operators

error appears. Can anybody see a problem here ?

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end textoperatorssinceiText 5

Mark Storer-2
Somewhere in your program, you've always had an unbalanced number of BT/ET pairs.  If you take one of your old PDFs (that was built by the older iTextSharp) and run it through Acrobat Pro's syntax checker, you'll find you have a problem.  Adobe's smart enough to Figure It Out, but there are quite a few other PDF viewers floating around these days that are not.
 
That's why I added the code to catch the unbalanced pairs, and why the rest of the team agreed that it was a good idea.  IIRC, the same sort of error is thrown with unbalanced q/Q pairs, though the verbage may be different...
 
And now I can't find where I put the check for BT/ET...
 
Ah yes... sanityCheck().  And because it's throwing during a newPage(), that means you have a BT without an ET somewhere in your page's text stream.  Not in the direct content, and changing that won't affect the text ContentByte one way or the other.
 
It's technically possible that we are throwing in error.  For Example:
 
q
  BT
   (blah)Tj
Q
 
I'm not sure how the PDF spec handles this Weird Case, or even if it has anything to say on the matter.  Lets see...
 
"A text object begins with the BT operator and ends with the ET operator, as shown in the Example, and described in Table 107. "
 
So the above content example is either illegal, or still inside a text object after the Q.  We're fiine... but there's some wiggle room here in the spec that makes me uncomfortable.  "Alarmed" even.  Leonard, am I reading this right?
 
Text state is also kinda independant of the regular graphic state.  Text attributes within a BT/ET pair are local to that text object.  BT/ET is kind of text's version of q/Q.  I would therefore hope that q BT Q parses as an unclosed text object, but a retentive reading of the quoted line would make q BT Q ET legal... like I said, "alarming".  I'm poking around in the q/Q verbage for something to support/reject this interpretation, to no avail.
 
These operators have been around since PDF 1.0... I'd be shocked if this question hasn't come up before.
 
 
--Mark Storer
  Senior Software Engineer
  Cardiff.com
 
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
 
 


From: Paulo Soares [mailto:[hidden email]]
Sent: Monday, August 30, 2010 9:16 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Error: Unbalanced begin/end textoperatorssinceiText 5

The only problem I can see here is that you are still ignoring the request for a simple, complete, standalone example. I'm ok you that, it's your problem, not mine.
 
Paulo
----- Original Message -----
Sent: Monday, August 30, 2010 4:59 PM
Subject: Re: [iText-questions] Error: Unbalanced begin/end text operatorssinceiText 5


Referring back to my first example with ColumnText(), the internal buffer of
the ColumnText ct reads just before the document is closed:

Canvas = {BT
1 0 0 1 163.67 479.06 Tm
/F1 26 Tf
(Astrologisches Porträt)Tj
ET
}

This looks pretty much ok, BT being short for BeginText(), then comes the
SetSimpleColumn(...), followed by the phrase (preceded by the chunk's font)
and ET for endText(). But, upon CloseDocument() the

Unbalanced begin/end text operators

error appears. Can anybody see a problem here ?

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.851 / Virus Database: 271.1.1/3091 - Release Date: 08/29/10 11:34:00


------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalanced begin/end textoperatorssinceiText 5

Leonard Rosenthol-3

A BT without a matching ET is an error.  If you have any other operators than those allowed inside BT/ET, it’s an error.

 

Leonard

 

From: Mark Storer [mailto:[hidden email]]
Sent: Monday, August 30, 2010 2:17 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Error: Unbalanced begin/end textoperatorssinceiText 5

 

Somewhere in your program, you've always had an unbalanced number of BT/ET pairs.  If you take one of your old PDFs (that was built by the older iTextSharp) and run it through Acrobat Pro's syntax checker, you'll find you have a problem.  Adobe's smart enough to Figure It Out, but there are quite a few other PDF viewers floating around these days that are not.

 

That's why I added the code to catch the unbalanced pairs, and why the rest of the team agreed that it was a good idea.  IIRC, the same sort of error is thrown with unbalanced q/Q pairs, though the verbage may be different...

 

And now I can't find where I put the check for BT/ET...

 

Ah yes... sanityCheck().  And because it's throwing during a newPage(), that means you have a BT without an ET somewhere in your page's text stream.  Not in the direct content, and changing that won't affect the text ContentByte one way or the other.

 

It's technically possible that we are throwing in error.  For Example:

 

q

  BT

   (blah)Tj

Q

 

I'm not sure how the PDF spec handles this Weird Case, or even if it has anything to say on the matter.  Lets see...

 

"A text object begins with the BT operator and ends with the ET operator, as shown in the Example, and described in Table 107. "

 

So the above content example is either illegal, or still inside a text object after the Q.  We're fiine... but there's some wiggle room here in the spec that makes me uncomfortable.  "Alarmed" even.  Leonard, am I reading this right?

 

Text state is also kinda independant of the regular graphic state.  Text attributes within a BT/ET pair are local to that text object.  BT/ET is kind of text's version of q/Q.  I would therefore hope that q BT Q parses as an unclosed text object, but a retentive reading of the quoted line would make q BT Q ET legal... like I said, "alarming".  I'm poking around in the q/Q verbage for something to support/reject this interpretation, to no avail.

 

These operators have been around since PDF 1.0... I'd be shocked if this question hasn't come up before.

 

 

--Mark Storer

  Senior Software Engineer

  Cardiff.com

 

import legalese.Disclaimer;

Disclaimer<Cardiff> DisCard = null;

 

 

 


From: Paulo Soares [mailto:[hidden email]]
Sent: Monday, August 30, 2010 9:16 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Error: Unbalanced begin/end textoperatorssinceiText 5

The only problem I can see here is that you are still ignoring the request for a simple, complete, standalone example. I'm ok you that, it's your problem, not mine.

 

Paulo

----- Original Message -----

Sent: Monday, August 30, 2010 4:59 PM

Subject: Re: [iText-questions] Error: Unbalanced begin/end text operatorssinceiText 5

 


Referring back to my first example with ColumnText(), the internal buffer of
the ColumnText ct reads just before the document is closed:

Canvas = {BT
1 0 0 1 163.67 479.06 Tm
/F1 26 Tf
(Astrologisches Porträt)Tj
ET
}

This looks pretty much ok, BT being short for BeginText(), then comes the
SetSimpleColumn(...), followed by the phrase (preceded by the chunk's font)
and ET for endText(). But, upon CloseDocument() the

Unbalanced begin/end text operators

error appears. Can anybody see a problem here ?

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.851 / Virus Database: 271.1.1/3091 - Release Date: 08/29/10 11:34:00


------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalancedbegin/end textoperatorssinceiText 5

Mark Storer-2
That's what I figured... thanks for the quick reply.
 
--Mark Storer
  Senior Software Engineer
  Cardiff.com
 
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
 
 


From: Leonard Rosenthol [mailto:[hidden email]]
Sent: Monday, August 30, 2010 11:19 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Error: Unbalancedbegin/end textoperatorssinceiText 5

A BT without a matching ET is an error.  If you have any other operators than those allowed inside BT/ET, it’s an error.

 

Leonard

 

From: Mark Storer [mailto:[hidden email]]
Sent: Monday, August 30, 2010 2:17 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Error: Unbalanced begin/end textoperatorssinceiText 5

 

Somewhere in your program, you've always had an unbalanced number of BT/ET pairs.  If you take one of your old PDFs (that was built by the older iTextSharp) and run it through Acrobat Pro's syntax checker, you'll find you have a problem.  Adobe's smart enough to Figure It Out, but there are quite a few other PDF viewers floating around these days that are not.

 

That's why I added the code to catch the unbalanced pairs, and why the rest of the team agreed that it was a good idea.  IIRC, the same sort of error is thrown with unbalanced q/Q pairs, though the verbage may be different...

 

And now I can't find where I put the check for BT/ET...

 

Ah yes... sanityCheck().  And because it's throwing during a newPage(), that means you have a BT without an ET somewhere in your page's text stream.  Not in the direct content, and changing that won't affect the text ContentByte one way or the other.

 

It's technically possible that we are throwing in error.  For Example:

 

q

  BT

   (blah)Tj

Q

 

I'm not sure how the PDF spec handles this Weird Case, or even if it has anything to say on the matter.  Lets see...

 

"A text object begins with the BT operator and ends with the ET operator, as shown in the Example, and described in Table 107. "

 

So the above content example is either illegal, or still inside a text object after the Q.  We're fiine... but there's some wiggle room here in the spec that makes me uncomfortable.  "Alarmed" even.  Leonard, am I reading this right?

 

Text state is also kinda independant of the regular graphic state.  Text attributes within a BT/ET pair are local to that text object.  BT/ET is kind of text's version of q/Q.  I would therefore hope that q BT Q parses as an unclosed text object, but a retentive reading of the quoted line would make q BT Q ET legal... like I said, "alarming".  I'm poking around in the q/Q verbage for something to support/reject this interpretation, to no avail.

 

These operators have been around since PDF 1.0... I'd be shocked if this question hasn't come up before.

 

 

--Mark Storer

  Senior Software Engineer

  Cardiff.com

 

import legalese.Disclaimer;

Disclaimer<Cardiff> DisCard = null;

 

 

 


From: Paulo Soares [mailto:[hidden email]]
Sent: Monday, August 30, 2010 9:16 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Error: Unbalanced begin/end textoperatorssinceiText 5

The only problem I can see here is that you are still ignoring the request for a simple, complete, standalone example. I'm ok you that, it's your problem, not mine.

 

Paulo

----- Original Message -----

Sent: Monday, August 30, 2010 4:59 PM

Subject: Re: [iText-questions] Error: Unbalanced begin/end text operatorssinceiText 5

 


Referring back to my first example with ColumnText(), the internal buffer of
the ColumnText ct reads just before the document is closed:

Canvas = {BT
1 0 0 1 163.67 479.06 Tm
/F1 26 Tf
(Astrologisches Porträt)Tj
ET
}

This looks pretty much ok, BT being short for BeginText(), then comes the
SetSimpleColumn(...), followed by the phrase (preceded by the chunk's font)
and ET for endText(). But, upon CloseDocument() the

Unbalanced begin/end text operators

error appears. Can anybody see a problem here ?

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.851 / Virus Database: 271.1.1/3091 - Release Date: 08/29/10 11:34:00

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.851 / Virus Database: 271.1.1/3091 - Release Date: 08/29/10 11:34:00


------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalancedbegin/end textoperatorssinceiText 5

Kevin Day
One thing to consider would be the case where multiple content streams get combined to construct a complete content stream.  In this case, it may *appear* that a cb stream has a leading BT with no trailing ET, and the trailing ET would wind up in a different stream.  I'm not sure if the sanity check properly accounts for this situation.


One thing the OP could do (if they really don't want to provide an example) is to disable the sanity check code, run their code, then use RUPS to grab the full content stream of the resultant PDF.  Then check to ensure that the BT and ET pairs are matched.  If they are, then the sanity check may very well be throwing in error - but it's going to take some example code to construct a use-case that really demonstrates this.

I suppose the OP could also take a look at the effective content stream generated by the pre-5 version of iText.



If you don't have RUPS available (I'm not sure if RUPS is ported to C# or not), the following class is handy for getting a quick dump of the effective content stream:

com/itextpdf/text/pdf/parser/PdfContentReaderTool.java


Probably tilting at windmills here, but who knows.

- K
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalancedbegin/end textoperatorssinceiText 5

alrts
My code passed also the SanityCheck().

However, I had page events running in the background for a footer, which I forgot about, and the problem was there, a missing end tag in certain cases. SanityCheck() showed me where. Thank you for that hint.

Thanks to Kevin's mentioning of "multiple content streams" I remembered the events.

iText 3.1.1 was tolerant to that, and so was GhostView and PDF Reader, but not iText 5.0.4.

Now this problem is solved, others are waiting: Images elsewhere, Hyphenation gone etc. ... Plenty of unproductive work waiting for me ...

Thank you all for your help!

Alexander
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalancedbegin/end textoperatorssinceiText 5

slg01
Hi,

When you mentioned having page events running in the background, what is that?  I am having a similar issue with unbalanced end/begin texts and I too did not have any where the error was occurring.  It was happening with a document.newPage().

How did you debug?

I am very very very new to itext so any direction would be great.

Thank you
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error: Unbalancedbegin/end textoperatorssinceiText 5

iText Info
Op 1/12/2010 18:15, slg01 schreef:
> Hi,
>
> When you mentioned having page events running in the background, what is
> that?
See chapter 5 of the Second Edition of iText in Action.
Page events implement the PdfPageEvent interface.
> I am having a similar issue with unbalanced end/begin texts and I too
> did not have any where the error was occurring.  It was happening with a
> document.newPage().
>
> How did you debug?
Check if you have an endText() for every beginText()
> I am very very very new to itext so any direction would be great.
If you're new to iText, why are you using low-level objects such as
beginText() and endText(). You should read the documentation; that is:
the OFFICIAL documentation, not some rogue example that tells newbies to
add text with showText().

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

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...