Hello!

I have an encrypted PDF File that was generated with OpenOffice and there 
included encryption-sets.
Then I would like to modify this "exists" and "encrypted" pdf with iText.

I wrote a small java program that stamped an "OverText" to all included
pages. But if I do so, I lost the encryption settings from OpenOffice
for this PDF. How can I fix this? I don't want to lose the openoffice - 
encryption settings...

Can anybody help me?

Here is my small code example...

...
...

System.out.println("Add watermark(s) now!");
        try {
            // we create a reader for a certain document
            String ownerPW = "PW";
            PdfReader reader = new PdfReader("infile-raw.pdf", 
ownerPW.getBytes()); //this is the original pdf - infile that is encrypted with 
openoffice

            int n = reader.getNumberOfPages();
            
            // we create a stamper that will copy the document to a new file
            PdfStamper stamp = new PdfStamper(reader, new 
FileOutputStream("infile-sec.pdf"));
            
            // adding content to each page
            int i = 0;
            PdfContentByte over_txt;    
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, 
BaseFont.WINANSI, BaseFont.EMBEDDED);

            while (i < n) {
                i++;
                
                PdfReader reader_pagesize = stamp.getReader();                  
                float PageSizeHeight = 
reader_pagesize.getPageSize(i).getHeight() / 2;
                float PageSizeWidth = reader_pagesize.getPageSize(i).getWidth() 
/ 2;
                
                // demo text over the existing page
                over_txt = stamp.getOverContent(i);             
                over_txt.beginText();
                over_txt.setFontAndSize(bf, 48);
                over_txt.setRGBColorFill(255,0,0);
                over_txt.showTextAligned(Element.ALIGN_CENTER,"DEMOMODE", 
PageSizeWidth, PageSizeHeight, 45);
                over_txt.endText();
            }
            // closing PdfStamper will generate the new PDF file
            stamp.close();
        }
        catch (Exception de) {
            de.printStackTrace();
        }

...
...

infile-sec.pdf is the new stamped pdf, but if I open it I lost all encryption 
informations...

Thanks for help!

Regards,

T. Hodes

-- 
249 Spiele für nur 1 Preis. Die GMX Spieleflatrate schon ab 9,90 Euro.
Neu: Asterix bei den Olympischen Spielen: http://flat.games.gmx.de

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar

Reply via email to