November 6th, 2010, 10:26 PM
IText PDF template help
Hey all, was just wondering if anyone would be able to help me out.
I'm currently creating a pdf document using the iText classes. All has gone fine but now I'm trying to export using a template document.
All I want the template document to be used for is a background image. So every page that is in the new document to contain the background. I have sort of got this working but I'm having a couple problems.
1. The template appears over the added content/text? I add the template first and then the content so not sure what happening there.
2. It only appears on the first page. I'm not sure how to make it appear on all the pages?
Heres what I'm doing
FileOutputStream outputStream = new FileOutputStream("file.pdf");
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
PdfReader reader = new PdfReader("template.pdf");
PdfImportedPage page = writer.getImportedPage(reader, 1);
PdfContentByte cb = writer.getDirectContent();
cb.addTemplate(page, 0, 0);
document.add(new Paragraph("Test Text");
November 7th, 2010, 10:14 PM
Does anyone know how to use iText to add an image to the background off all pages within a pdf. Can't really find a solution anywhere.
November 7th, 2010, 10:36 PM
All good people, I've got it working. For those wondering, I justed used a water mark. Just add it before you call document.open() and it will add to all pages
Originally Posted by doush.
headache gone now
November 8th, 2012, 01:35 PM
Getting the content in the background
To get the content to appear below the text (as a background image) use writer.getDirectContentUnder()
See this page for more information ( http :// stderr . org/doc/libitext-java-doc/www/tutorial/ch10.html
I don't know how to repeat on every page yet.