|
Dear iText list members,
Can you please
tell me whether I can read a pdf file and encrypt it and overwrite the pdf file
with the same name. I just want to read the pdf file and show the user
the encrypted pdf without saving it to the hard disk.
This is my code
PdfReader reader = new PdfReader("test.pdf");
// retrieve the total number of pages int n = reader.getNumberOfPages(); Document document = new Document(psize, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Encypttest.pdf"));
writer.setEncryption(PdfWriter.STRENGTH128BITS, "y", "y",PdfWriter.AllowFillIn); document.open(); // add content
PdfContentByte cb = writer.getDirectContent(); int i = 0; int p = 0; //System.out.println("There are " + n + " pages in the document."); while (i < n) { document.newPage(); p++; i++; PdfImportedPage page1 = writer.getImportedPage(reader, i); cb.addTemplate(page1, .5f, 0, 0, .5f, 0, height / 2); //System.err.println("processed page " + i); }
// step 5: we close the document document.close(); Here I read test.pdf file and
encrypt it and save as Encypttest.pdf
. I would preffer not to save the ecrypted
file. without saving just show it to the user..Can you please tell me
whether that is possible? if so how can I do it...
Regards,
Yamuna
|
- RE: [iText-questions] iText to Convert Files to PDF -urgent Yamuna Bellana
