Hi all.

I'm a new iText user... what I need to do, given a pdf is:
copy the first page (so, starting from a 5-pages pdf I need to end
with a 6-pages pdf) and stamp some text on it.

Toying around the apis, all I made is a method like this:

(original is an InputStream with the original pdf)
...
PdfReader reader = new PdfReader(original);
int n = reader.getNumberOfPages();
if (n == 0)
    return original; // no pages

ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamp = new PdfStamper(reader, baos);

// copy the first page
byte[] page1 = reader.getPageContent(1);  // content of the first page
stamp.insertPage(1, reader.getPageSize(1));     // insert a very first blank 
page
reader.setPageContent(1, page1);        // copy the content of the "old" first 
page

// "stamp" the "new" first page
PdfContentByte layer_over = stamp.getOverContent(1);
layer_over.beginText();
layer_over.setFontAndSize(
    BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
BaseFont.EMBEDDED),
    this.text_size);
layer_over.moveText(this.left_spacing, this.bottom_spacing);
layer_over.setLeading(this.text_size);
layer_over.setTextRenderingMode(
    PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE_CLIP);
for (final String text: texts)
    layer_over.newlineShowText(text);
layer_over.endText();

stamp.close();
return new ByteArrayInputStream(baos.toByteArray());

but acrobat reader say it cannot find the right font for the generated
pdf (?) and show me the copy of the first page with some strange
characters...

-- 
Vito De Tullio - [email protected]

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to