Quantcast

newline handling inside chunk/phrase

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

newline handling inside chunk/phrase

pier luigi zanotti
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 .

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: newline handling inside chunk/phrase

Raf Hens
On 6/07/2012 8:58, pier luigi zanotti wrote:

> 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

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: newline handling inside chunk/phrase

searchengine27
In reply to this post by pier luigi zanotti
Does anyone know what version this was fixed in?
Loading...