You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Richard van Heest <ri...@solcon.nl> on 2011/07/11 11:22:31 UTC
writing text in an PDF-doc
Good morning,
I'm already using the PDFBox-library for some months. Initially I had some
problems, but they are already solved. Now I have a new thing:
text-alignment. Normally the text is lined out on the left side. I made a
method which writes the text (String tekst) on a page (int paginanr) and a
position (Punt punt) in a given Font (Font font). I made these classes Punt
en Font on my own, so it doesn't refer to any class of your PDFBox-library.
(see also the code in the box)
I found that the position (Punt punt) you have to choose is the left-down
location of the string. But now I want to write text starting from the
right. In other words, I want to write right-aligned text.
So in this way J
Is there any possibility in the PDFBox-library to do this?
Please help me!
Kind regards,
Richard van Heest
Middelharnis - The Netherlands.
public void schrijfTekst(String tekst, int paginanr, Punt punt, Font font) {
PDPage page = this.getPage(paginanr);
PDPageContentStream stream;
try {
stream = new PDPageContentStream(this.document, page, true,
false);
stream.setFont(font.getFont(), font.getSize());
stream.setNonStrokingColor(Color.black);
stream.beginText();
stream.moveTextPositionByAmount(new Float(100*punt.getX()/3.25),
new Float(100*punt.getY()/3.25));
stream.drawString(tekst);
stream.endText();
stream.close();
}
catch(IOException e) {
e.printStackTrace();
}
}