On 19/08/2012 1:07, Peter Stein wrote:
| cb.saveState();
cb.beginText();
cb.moveText(x, y);
cb.setFontAndSize(bf, 12);
cb.showText(text);
cb.endText();
cb.restoreState();|
Or: if you want to do this in one line:
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase(text, new
Font(bf, 12)), x, y, 0);
The main difference technically:
- with ColumnText.showTextAligned(), you creating the syntax generated
with your 7 lines over and over again for each line you write.
- with your 7 lines, you can sometimes reduces the number of operands
needs to draw different lines at different places.
The main difference practically:
- with ColumnText.showTextAligned(), you don't have to worry about
getting the syntax right.
- with your 7 lines, you need to make sure all the graphics state and
text state operators are nicely balanced.
|
I have added possibilities to add my text from my datasources to this method
and it's really working great. The result looks very promising to me and so is
only one task for me left at the moment:
I need to add specfic background colors to my text (not font color!) that I'm
moving and placing in the method shown above.|
And here's why I explained the difference:
- with ColumnText.showAligned(), you can create a Phrase that consists
of Chunks, and with Chunks you have a method to define the background color.
- with your approach, you have to use graphics state operators to change
the fill color (but don't forget to change it back before adding text,
or your text will have the same color as the background), you'll have to
calculate the length of the text, then draw and fill a rectangle that
fits nicely under the text. Also make sure that you don't use graphics
state operators that aren't allowed in text state inside the BT-ET block.
|My research didn't provide me any beginner-friendly information about this
task so I would be really happy if you could help me solve this. I also read
something during my research that it could be possible to (somehow) create a
rectangle and write the text above it.|
Your research didn't include reading "iText in Action - Second Edition" ;-)
That means that you'll have to do with examples:
http://itextpdf.com/themes/keyword.php?id=123
http://itextpdf.com/themes/keyword.php?id=64
http://itextpdf.com/themes/keyword.php?id=60
and so on...
|If possible: can you modify my example in a way that adds a background color
to the added example-text (so at the same coordinates)?|
Yes, you can, but I'd probably use a different approach. However, I
don't know the exact requirements. For instance: one could easily define
the rectangle first and then add the text inside the rectangle, so that
the text wraps if the width of the rectangle isn't sufficient, but maybe
that's not one of your requirements.
------------------------------------------------------------------------------
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
[email protected]
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