Anita is correct. It actually works very well. I would add that the line
page.getContents().getStream();
it may be a stranger, and PDPage is amortized in favor of PDPageable in newer versions (and is mainly used for printing), but the code will work for your purpose without switching from iText (and in the end you initially asked about PDFBox).
Remember to include the fix that Anita gave to create extra bits in the creation of the contentstream:
PDPageContentStream contentStream = new PDPageContentStream( document, page, true, true);
You should also remember that you are likely to create and close streams for each print section that you place on top of the pdf on which you overlay the text. You need to close both streams and the document so that the buffers are written, otherwise you will not see the changes.
In addition, for those who are trying to find out, there are several options for downloading libraries from apache for pdfbox. I find it easiest to use (for now) a file called pdfbox-app-1.8.10.jar (which I use in my JSF applications). It already includes other libraries that are hard-wired to pdfbox, which you also need to download to do anything meaningful.
source share