pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Ternes <KTer...@thegeneral.com>
Subject RE: Two problems with merged documents.
Date Tue, 22 Sep 2015 19:09:24 GMT
Yes, the last one, output/3-flattened-merged-A.pdf is missing field values.

-----Original Message-----
From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
Sent: Tuesday, September 22, 2015 1:35 PM
To: users@pdfbox.apache.org
Subject: Re: Two problems with merged documents.

Hi Kevin,

just to be sure - the individual files are OK but the merged one is the one where the content
is missing?

BR
Maruan

> Am 22.09.2015 um 19:52 schrieb Kevin Ternes <KTernes@thegeneral.com>:
> 
> I still have two problems with the merge.
> First is the problem of losing field values after the merge which I have had all along.
> The second is new and is that when I open the merge document with Adobe Reader XI (11.0.12)
I see a popup saying "Out of Memory".
> That popup usually appears after scrolling down the merged document.
> 
> Four source documents are here:
> https://dl.dropboxusercontent.com/u/3103884/dev/EndFaxCover_CA.pdf
> https://dl.dropboxusercontent.com/u/3103884/dev/EndDetails_CA.pdf
> https://dl.dropboxusercontent.com/u/3103884/dev/EndExclDrv_CA.pdf
> https://dl.dropboxusercontent.com/u/3103884/dev/EndSig_CA.pdf
> 
> The following code loads and populates the documents and then flattens and merges them.
> Whether or not the flatten() is called does not make a difference.  
> If someone can have a look, I'd really appreciate it.
> 
> import java.io.File;
> import java.util.Date;
> 
> import org.apache.pdfbox.multipdf.PDFMergerUtility;
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
> import org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox;
> import org.apache.pdfbox.pdmodel.interactive.form.PDTextField;
> 
> public class PDFBoxRun {
> 
>  public static void main(String[] args) {
> 
>    System.out.println("Running...");
>    PDDocument pdDocumentA = null;
>    PDDocument pdDocumentB = null;
>    PDDocument pdDocumentC = null;
>    PDDocument pdDocumentD = null;
> 
>    try {
> 
>      pdDocumentA = PDDocument.load(new File("template/EndFaxCover_CA.pdf"));
>      PDAcroForm acroForm = pdDocumentA.getDocumentCatalog().getAcroForm();
>      ((PDCheckbox) acroForm.getField("boxUMPD")).check();
>      ((PDTextField) acroForm.getField("printDate")).setValue("09/11/2015");
>      ((PDTextField) acroForm.getField("polNum")).setValue("22-CA-116850A");
>      ((PDTextField) acroForm.getField("quoteEffDt")).setValue("09/11/2015");
>      ((PDTextField) acroForm.getField("agencyName")).setValue("THE MAJOR123 AUTO INS
SVCS, INC");
>      ((PDTextField) acroForm.getField("quoteNum")).setValue("2917812");
> 
>      pdDocumentB = PDDocument.load(new File("template/EndDetails_CA.pdf"));
>      acroForm = pdDocumentB.getDocumentCatalog().getAcroForm();
>      ((PDTextField) acroForm.getField("hdrAuditFld")).setValue("Generated at " + new
Date() + ", User: DEVUSER/PDFBoxRun]");
>      ((PDTextField) acroForm.getField("quoteOrBindHdr")).setValue("Policy Change Request
(Quote Only)");
>      ((PDTextField) acroForm.getField("endEffDt")).setValue("09/04/2015");
>      ((PDTextField) acroForm.getField("endEffTime")).setValue("11:59 PM");
>      ((PDTextField) acroForm.getField("polnum")).setValue("22-CA-116850A (quote 2917812)");
>      ((PDTextField) acroForm.getField("agencyDesc")).setValue("THE MAJOR123 AUTO INS
SVCS, INC (998888)");
>      ((PDTextField) acroForm.getField("hInsName")).setValue("EXAMPLE N SUREDNAME");
>      ((PDTextField) acroForm.getField("BIPDLim")).setValue("$15,000/$30,000/$10,000");
>      ((PDTextField) acroForm.getField("MedPay")).setValue("No coverage");
>      ((PDTextField) acroForm.getField("UMBI")).setValue("$15,000/$30,000");
>      ((PDTextField) acroForm.getField("UMPD")).setValue("No coverage");
> 
>      pdDocumentC = PDDocument.load(new File("template/EndSig_CA.pdf"));
>      acroForm = pdDocumentC.getDocumentCatalog().getAcroForm();
>      ((PDTextField) acroForm.getField("hdrAuditFld")).setValue("Generated at " + new
Date() + ", User: DEVUSER/PDFBoxRun");
>      ((PDTextField) acroForm.getField("quoteOrBindHdr")).setValue("Policy Change Request
(Quote Only)]");
>      ((PDTextField) acroForm.getField("endEffDt")).setValue("09/04/2015");
>      ((PDTextField) acroForm.getField("endEffTime")).setValue("11:59 PM");
>      ((PDTextField) acroForm.getField("polnum")).setValue("[22-CA-116850A (quote 2917812)");
>      ((PDTextField) acroForm.getField("agencyDesc")).setValue("THE MAJOR123 AUTO INS
SVCS, INC (998888)");
>      ((PDTextField) acroForm.getField("hInsName")).setValue("EXAMPLE N SUREDNAME");
>      ((PDTextField) acroForm.getField("umpdRejSigAppl")).setValue("XXXX");
> 
>      pdDocumentD = PDDocument.load(new File("template/EndExclDrv_CA.pdf"));
>      acroForm = pdDocumentD.getDocumentCatalog().getAcroForm();
>      ((PDTextField) acroForm.getField("hdrAuditFld")).setValue("Generated at  " + new
Date() + ", User: DEVUSER/PDFBoxRun");
>      ((PDTextField) acroForm.getField("quoteOrBindHdr")).setValue("Policy Change Request
(Quote Only)]");
>      ((PDTextField) acroForm.getField("endEffDt")).setValue("09/04/2015");
>      ((PDTextField) acroForm.getField("endEffTime")).setValue("11:59 PM");
>      ((PDTextField) acroForm.getField("hInsName")).setValue("EXAMPLE N SUREDNAME");
>      ((PDTextField) acroForm.getField("polnum")).setValue("[22-CA-116850A (quote 2917812)");
>      ((PDTextField) acroForm.getField("agencyDesc")).setValue("THE MAJOR123 AUTO INS
SVCS, INC (998888)");
> 
>      pdDocumentA.save("output/0-Afilled-EndFaxCover_CA.pdf");
>      pdDocumentB.save("output/0-Bfilled-EndDetails_CA.pdf");
>      pdDocumentC.save("output/0-Cfilled-EndSig_CA.pdf");
>      pdDocumentD.save("output/0-Dfilled-EndExclDrv_CA.pdf");
> 
>      pdDocumentA.getDocumentCatalog().getAcroForm().flatten();
>      pdDocumentB.getDocumentCatalog().getAcroForm().flatten();
>      pdDocumentC.getDocumentCatalog().getAcroForm().flatten();
>      pdDocumentD.getDocumentCatalog().getAcroForm().flatten();
> 
>      pdDocumentA.save("output/2-Aflattened-EndFaxCover_CA.pdf");
>      pdDocumentB.save("output/2-Bflattened-EndDetails_CA.pdf");
>      pdDocumentC.save("output/2-Cflattened-EndSig_CA.pdf");
>      pdDocumentD.save("output/2-Dflattened-EndExclDrv_CA.pdf");
> 
>      System.out.println("Merging...");
>      PDFMergerUtility mergerUtility = new PDFMergerUtility();
>      mergerUtility.appendDocument(pdDocumentA, pdDocumentB);
>      mergerUtility.appendDocument(pdDocumentA, pdDocumentC);
>      mergerUtility.appendDocument(pdDocumentA, pdDocumentD);
>      System.out.println("Saving merged document as output/3-flattened-merged-A.pdf");
>      pdDocumentA.save("output/3-flattened-merged-A.pdf");
> 
>      System.out.println("Done.");
>    } catch (Exception ex) {
>      System.err.println("Caught " + ex);
>      ex.printStackTrace();
>    } finally {
>      close(pdDocumentA);
>      close(pdDocumentB);
>      close(pdDocumentC);
>      close(pdDocumentD);
>    }
>  }
> 
>  static void close(PDDocument doc) {
>    if (null != doc) {
>      try {   doc.close();   } catch (Exception ex) {      }
>    }
>  }
> 
> }


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message