Using: iText v 5.4.3 - Jdk 1.7_u25 32bit First, read the PDF format specification v1.7, section 3.4.5 page 98 http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf Talks about "Incremental Updates." Read this section for more info of what I'm talking here.
Second, in my previous posts when I referred to pdfStamper.extractRevision () I was actually referring to me pdfStamperInstance.getAcroFields().extractRevision(); I edited my previous posts to make it clear. Third, let it clear what I'm trying to do: I have files that are signed multiple times. The first time the file is requested flow is as follows: 1 - I get a template server. 2 - I open this file fill some fields and sign. Saved and closed the file. 3 - We reopen this file and try to extract the file revision. 4 - Mando InputStream to the revision to the server. 5 - The server receives the inputStream and must make a revision in the append template. If the second (or later) file to be sent will be the last revision. Below the code: import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.security.GeneralSecurityException; import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.AcroFields; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfStamper; public class ItextIncrementalUpdater { public static void main(String[] args) throws IOException, DocumentException, GeneralSecurityException { //------------------------------------------------- // Filling and signing pdf //Here we simulate a server sending the template and //the client filling the fields and sign //------------------------------------------------- System.out.println("#> FILLING PDF"); File pdfTemplate = new File("template.pdf"); FileInputStream pdfTemplateFis = new FileInputStream(pdfTemplate); byte[] pdfTemplateFisBuffer = new byte[pdfTemplateFis.available()]; pdfTemplateFis.read(pdfTemplateFisBuffer); pdfTemplateFis.close(); File outputFilled1Pdf = new File("filled1.pdf"); FileOutputStream outputFilled1PdfFos = new FileOutputStream(outputFilled1Pdf); PdfReader reader = new PdfReader(pdfTemplateFisBuffer); PdfStamper stamper = new PdfStamper(reader, outputFilled1PdfFos); AcroFields fields = stamper.getAcroFields(); fields.setField("FIELD1", "VALUE_FOR_FIELD_1"); stamper.close(); reader.close(); outputFilled1PdfFos.flush(); outputFilled1PdfFos.close(); System.out.println("#> SIGNING PDF"); File outputSignedPdf = new File("outputSig1.pdf"); //ItextSmartCardPdfSigner is my signer class ItextSmartCardPdfSigner signer = new ItextSmartCardPdfSigner("smartCardPasswordHere".toCharArray()); signer.sign(outputFilled1Pdf, outputSignedPdf, "reason", "local", "contact", 0, 1, "SignatureFieldNameHere"); System.out.println("#> PDF SIGNED"); //------------------------------------------------- // Extracting Revision //Here we intend to extract the revison on the //client side to send only the revision back to server //------------------------------------------------- System.out.println("#> LOADING SIGNED FILE"); FileInputStream pdfSignedFis = new FileInputStream(outputSignedPdf); byte[] pdfSignedBuffer = new byte[pdfSignedFis.available()]; pdfSignedFis.read(pdfSignedBuffer); pdfSignedFis.close(); File revisionFile = new File("revision.pdf"); FileOutputStream revisionFos = new FileOutputStream(revisionFile); PdfReader reader2 = new PdfReader(pdfSignedBuffer); PdfStamper stamper2 = new PdfStamper(reader2, revisionFos); System.out.println("#> EXTRACTING REVISION"); AcroFields revisionFields = stamper2.getAcroFields(); InputStream revisionIs = revisionFields.extractRevision("Sig1"); //<-- revision is supposed to be here System.out.println("#> INPUTSTREAM AVAIBLE COUNT : " + revisionIs.available()); byte[] revisionBuffer = new byte[revisionIs.available()]; revisionIs.read(revisionBuffer); revisionIs.close(); System.out.println("##> REVISION SIZE " + revisionBuffer.length); String revisionStr = new String(revisionBuffer); System.out.println(revisionStr); stamper2.close(); reader2.close(); revisionFos.flush(); revisionFos.close(); System.out.println("#> END OF REVISION EXTRACT"); //------------------------------------------------- // Incremental Update (!i want to know how to do this part!) //Here we simulate the server received the revision //and is trying to append the revision on the template //------------------------------------------------- System.out.println("#> STARTING THE INCREMENTAL UPDATE"); FileInputStream templateFis = new FileInputStream(pdfTemplate); byte[] templateFisBuffer = new byte[templateFis.available()]; templateFis.read(templateFisBuffer); templateFis.close(); File outputFile = new File("out.pdf"); FileOutputStream fos = new FileOutputStream(outputFile); fos.write(templateFisBuffer); fos.flush(); fos.write(revisionBuffer); fos.flush(); fos.close(); System.out.println("#> END OF THE INCREMENTAL UPDATE"); } } -- View this message in context: http://itext-general.2136553.n4.nabble.com/Pdf-Incremental-Updates-tp4659069p4659093.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php