See PdfStamper.createSignature(PdfReader reader, OutputStream os, char pdfVersion, File tempFile).
Paulo ----- Original Message ----- From: "Eneko González" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Thursday, October 05, 2006 9:20 AM Subject: [iText-questions] Memory Problem > Hi all, > > I have a class that concatenates files, and signs the resulting PDF. The > concatenation seems to work OK, but when I try to sign the PDF, i get a > OutOfMemoryError. > > It's true that this PDF has 97 pages (33 Mbytes) but i think this > shouldn't be a problem to iText, so the problem must be in my code, but > i can't see it. > > Can anyone help me? > > /** --------------- Concatenation ----------------- */ > private void concatPDF(ArrayList ficheros, String pathDest, String > nameDest) throws IOException, DocumentException { > int pageOffset = 0; > ArrayList master = new ArrayList(); > int f = 0; > Document document = null; > PdfCopy writer = null; > FileOutputStream out = null; > while (f < ficheros.size()) { > PdfReader reader = new PdfReader(PATH_FILES_SINGLEPDF + > File.separator + ficheros.get(f)); > reader.consolidateNamedDestinations(); > int n = reader.getNumberOfPages(); > pageOffset += n; > if (f == 0) { > // step 1: creation of a document-object > document = new Document(reader.getPageSizeWithRotation(1)); > // step 2: we create a writer that listens to the document > out = new FileOutputStream(pathDest + File.separator + nameDest); > writer = new PdfCopy(document, out); > // step 3: we open the document > document.open(); > } > PdfImportedPage page; > for (int i = 0; i < n; ) { > ++i; > page = writer.getImportedPage(reader, i); > writer.addPage(page); > } > writer.freeReader(reader); > f++; > } > if (master.size() > 0) { > writer.setOutlines(master); > } > // step 5: we close the document > document.close(); > writer.close(); > if (out!=null) { > out.close(); > } > } > > /** --------------- Signing----------------- */ > > private void signPDF(String src, String dst) throws IOException, > DocumentException, KeyStoreException, NoSuchAlgorithmException, > CertificateException, UnrecoverableKeyException { > FileOutputStream out = new FileOutputStream(dst); > PdfReader reader = new PdfReader(src); > PdfStamper stamp = PdfStamper.createSignature(reader, out, '\0'); > KeyStore ks = KeyStore.getInstance("pkcs12"); > ks.load(new FileInputStream("certificado.pfx"), "XXXX".toCharArray()); > String alias = (String)ks.aliases().nextElement(); > PrivateKey key = (PrivateKey)ks.getKey(alias, "XXXX".toCharArray()); > Certificate[] chain = ks.getCertificateChain(alias); > PdfSignatureAppearance sap = stamper.getSignatureAppearance(); > sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED); > sap.setReason("Factura"); > sap.setLocation("Bilbao"); > sap.setSignDate(new GregorianCalendar()); > stamp.close(); > out.close(); > } > > Thanks in advance, > > -- > Keko > > "Ezinbestekoa ez bada, ez imprimitu mezu hau edo honekin batera > doazkizun dokumentuak. Lagundu ingurumena zaintzen, denon ardura da." > > "No imprima este mensaje o sus documentos adjuntos, a no ser que sea > verdaderamente necesario. Colaborar a respetar el Medio Ambiente es > responsabilidad nuestra." > > "Please don't print this e-mail or its attachments, unless it is > absolutely necessary. It is our responsibility to respect the > environment." > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
