Discussion:
[iText-questions] newline handling inside chunk/phrase
pier luigi zanotti
2012-07-06 06:58:42 UTC
Permalink
I'm a bit confused about newline handling in chunks text. The following
code:

Paragraph para = new Paragraph();
para.add(new Chunk(" A"));
para.add(new Chunk("\n B"));
para.add(new Chunk("\n C"));
document.add(para);

add a paragraph of 3 lines, where the first line in the resulting pdf
document is slightly shifted to the right, while I was expecting that
the lines began at the same exact horizontal position. Note that every
letter "A", "B", "C" is preceded by two space char.
If I use a newline also in the first Chunk, the three lines are
perfectly horizontally aligned in the output document:

Paragraph para = new Paragraph();
para.add(new Chunk("\n A"));
para.add(new Chunk("\n B"));
para.add(new Chunk("\n C"));
document.add(para);


So the question is: why the presence of a newline character on a chunk
text affect the horizontal position of the text itself?

The version of iText I'm using is 5.2.1 .
Raf Hens
2012-07-06 13:58:59 UTC
Permalink
Post by pier luigi zanotti
So the question is: why the presence of a newline character on a chunk
text affect the horizontal position of the text itself?
The version of iText I'm using is 5.2.1 .
This is indeed an issue in iText, also present in 5.3.0. When handling
the word wrapping, a space gets eaten where it shouldn't.
It will be fixed in the next release.

As a workaround, you can put your newlines in a separate chunk (or use
Chunk.NEWLINE):

para.add(new Chunk(" A"));
para.add(Chunk.NEWLINE);
para.add(new Chunk(" B"));
para.add("\n");
para.add(new Chunk(" C"));


Best regards,
Raf
searchengine27
2016-07-18 19:15:19 UTC
Permalink
Does anyone know what version this was fixed in?



--
View this message in context: http://itext.2136553.n4.nabble.com/newline-handling-inside-chunk-phrase-tp4655550p4661065.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
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...