pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Text overlap
Date Mon, 09 May 2016 06:33:36 GMT
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).


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

View raw message