You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Ivan Ridao Freitas <in...@ivanrf.com> on 2016/05/09 00:30:44 UTC

Text overlap

Hi, I'm designing an invoice with PDFBox. The only doubt I have is how 
to control text overlapping?
For example, if one line has a text at (x=10) and another at (x=100), 
how can I prevent the first text to overlap the second one.
I'm adding text with:
         content.beginText();
         content.newLineAtOffset(x, y);
         content.showText(text);
         content.endText();

I know how to calculate the string width and I could cut it until it 
fits, but is that the only approach?
Should I consider inserting a form field and then set the text to a 
PDTextField?

Thanks,
Ivan

Re: Text overlap

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 09.05.2016 um 02:30 schrieb Ivan Ridao Freitas:
> Hi, I'm designing an invoice with PDFBox. The only doubt I have is how 
> to control text overlapping?
> For example, if one line has a text at (x=10) and another at (x=100), 
> how can I prevent the first text to overlap the second one.
> I'm adding text with:
>         content.beginText();
>         content.newLineAtOffset(x, y);
>         content.showText(text);
>         content.endText();
>
> I know how to calculate the string width and I could cut it until it 
> fits, but is that the only approach?
> Should I consider inserting a form field and then set the text to a 
> PDTextField?

What I've seen in PDFs "in the wild" is this:

- save graphics
- rectangle
- set clipping path
- draw your text
- restore graphics


Another strategy, if you want to avoid cutting off, is to use a smaller 
font if the text gets too large, or a narrow  font (Arial narrow).

Tilman

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org