Hi everyone.
My name is Paul, I'm new to iText (yes!, I am a newby) and I'd like to ask
you one thing.
My goal is very simple: I already have a PDF file and I only want to attach
a Javascript to it (I'd like to have that particular document printed on
opening).
I wrote down some working code, but I'd like to know if there is a simpler
and quicker way to do it (e.g., I noticed the PdfStamper class, but I didn't
understand how it works).
Best Regards,
Paolo


        ByteArrayOutputStream outputByteArray = new ByteArrayOutputStream();
        PdfReader reader = new PdfReader(outputStreamBuffer.toByteArray()); // this
is the original PDF file

        int n = reader.getNumberOfPages();
        Rectangle psize = reader.getPageSizeWithRotation(1);

        Document document = new Document(psize);
        PdfWriter writer = PdfWriter.getInstance(document, outputByteArray);
        document.open();
        PdfContentByte cb = writer.getDirectContent();

        int p = 0;
        while (p < n) {
                document.newPage();
                PdfImportedPage page = writer.getImportedPage(reader, ++p);
                cb.addTemplate(page, .95f, 0, 0, .95f, 0, 0);
        }
        writer.addJavaScript(ONLOAD_SCRIPT_PDF);

        document.close();
        outputByteArray.writeTo(outChannel);



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to