Thomas Kuechenthal wrote:

> //reading the  PDF that contains the text
> PdfReader original = new PdfReader("MyOriginalLetter.pdf");
> 
> //reading the letterhead PDF
> PdfReader letterhead = new PdfReader("MyLetterhead.pdf");
> 
> Document document = new Document();

Be careful! The line above creates an A4 document.
What are the dimensions of the original document?
Maybe you should use:
   Document document = new Document(original.getPageSizeWithRotation(1));
This way the first page of the new document has the
same dimensions of the first page of the original document.

> // making new PDF Document
> PdfWriter writer = PdfWriter.getInstance(document, new
> FileOutputStream("MyNewLetter.pdf"));
> 
> document.open();
> 
> PdfContentByte cb = writer.getDirectContent();
> 
> // shall I first import the letterhead?
> PdfImportedPage letterheadImport=writer.getImportedPage(letterhead, 1);
> cb.addTemplate(letterheadImport, ?,?);
> 
> // and then the text PDF?
> PdfImportedPage originalImport=writer.getImportedPage(original, 1);
> cb.addTemplate(originalImport, ?,?);
> ...

> - I'm not certain about in what order I must add the templates to the
> PdfContentByte. First the letterhead and then the text? Or vice versa?

If you only use getDirectContent; add the letterhead first,
then the text. You could also use getDirectContentUnder;
add the letterhead to the 'under' content, and the text
to the 'upper' content. It's your choice.

> - I'm not certain about the parameters of the addTemplate() method. Both
> documents are DIN A4 sized. What parameters must I use?

OK, this answers my initial question; we're working with A4
documents; in this case, you can use x = 0; y = 0.

> - When I add the letterhead first and then the text, the letterhead is
> hidden by the text.

Of course it is. Did you expect something else?
If you have a typewriter, and you insert paper with
a letter head, you normally don't type text that covers
your letterhead. When creating your original PDF, you
should have thought of that...

> When I first add the text and then the letterhead,
> the watermark of the letterhead is in front of the text and thus hiding
> the text.

That's normal, isn't it?

> Thank you
I don't know what you were expecting.

Do you want to make the letterhead transparent so that
you can see the letterhead and the text? They will still
overlap, but you will be able to see through the letterhead
(of course, if there's a header, it will be transparent too).

Or do you want to shrink the text so that it fits in a
rectangle that is smaller than the letterhead?
That's possible too, but you'll have to define the rectangle;
iText doesn't know where you want to insert the text.

br,
Bruno

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to