Hi all,
for the archives, I've written a small proof-of-concept
program which couples FOP and iText in order to provide
PDF encryption. Watermarking and everything else, possibly
even Henrik Holle's total page count problem, could be
done in a similar way.
Most of the iText code is directly copied from Lowagie's
enctryption utility.

Home page: http://www.lowagie.com/iText/

   public static void main(String args[]) {
     try {
       ByteArrayOutputStream fopout=new ByteArrayOutputStream();
       FileOutputStream outfile=new FileOutputStream(args[2]);
       Driver driver =new Driver();
       driver.setOutputStream(fopout);
       driver.setRenderer(Driver.RENDER_PDF);
       Transformer transformer=TransformerFactory.newInstance().newTransformer(new 
StreamSource(new File(args[1])));
       transformer.setParameter("page-count","#");
       transformer.transform(new StreamSource(new File(args[0])), new 
SAXResult(driver.getContentHandler()));
       PdfReader reader = new PdfReader(fopout.toByteArray());
       int n = reader.getNumberOfPages();
       Document document = new Document(reader.getPageSizeWithRotation(1));
       PdfWriter writer = PdfWriter.getInstance(document, outfile);
       writer.setEncryption(PdfWriter.STRENGTH40BITS, "pdf", null, 
PdfWriter.AllowCopy);
       document.open();
       PdfContentByte cb = writer.getDirectContent();
       PdfImportedPage page;
       int rotation;
       int i = 0;
       while (i < n) {
         i++;
         document.setPageSize(reader.getPageSizeWithRotation(i));
         document.newPage();
         page = writer.getImportedPage(reader, i);
         rotation = reader.getPageRotation(i);
         if (rotation == 90 || rotation == 270) {
           cb.addTemplate(page, 0, -1f, 1f, 0, 0, 
reader.getPageSizeWithRotation(i).height());
         }
         else {
           cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
         }
         System.out.println("Processed page " + i);
       }
       document.close();
     }
     catch( Exception e) {
       e.printStackTrace();
     }
   }

Have fun
J.Pietschmann


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to