Return-Path: X-Original-To: apmail-pdfbox-users-archive@www.apache.org Delivered-To: apmail-pdfbox-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3330217CE9 for ; Tue, 22 Sep 2015 19:10:16 +0000 (UTC) Received: (qmail 5152 invoked by uid 500); 22 Sep 2015 19:10:01 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 5126 invoked by uid 500); 22 Sep 2015 19:10:01 -0000 Mailing-List: contact users-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@pdfbox.apache.org Delivered-To: mailing list users@pdfbox.apache.org Received: (qmail 5104 invoked by uid 99); 22 Sep 2015 19:10:01 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Sep 2015 19:10:01 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id DDA3F180997 for ; Tue, 22 Sep 2015 19:10:00 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.002 X-Spam-Level: * X-Spam-Status: No, score=1.002 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, LOTS_OF_MONEY=0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id wTq2PWVO-vzI for ; Tue, 22 Sep 2015 19:09:48 +0000 (UTC) Received: from us-smtp-delivery-105.mimecast.com (us-smtp-delivery-105.mimecast.com [63.128.21.105]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 4F4FC23066 for ; Tue, 22 Sep 2015 19:09:48 +0000 (UTC) Received: from hubca1.pgac.com (email.pgac.com [12.68.231.192]) (Using TLS) by us-smtp-1.mimecast.com with ESMTP id us-mta-14-Tv7QDNYrROOd3PH-KZuHnA-49; Tue, 22 Sep 2015 15:09:44 -0400 Received: from EX07MAIL3.pgac.com ([172.23.10.5]) by hubca1.pgac.com ([172.23.10.3]) with mapi; Tue, 22 Sep 2015 14:09:24 -0500 From: Kevin Ternes To: "users@pdfbox.apache.org" Date: Tue, 22 Sep 2015 14:09:24 -0500 Subject: RE: Two problems with merged documents. Thread-Topic: Two problems with merged documents. Thread-Index: AdD1Zm7vcDxQ6OtZSe6sUacORdas7wAA5cdw Message-ID: References: <9F1F4ED6-E954-4AF4-BF9B-119930A93CAA@fileaffairs.de> In-Reply-To: <9F1F4ED6-E954-4AF4-BF9B-119930A93CAA@fileaffairs.de> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 X-MC-Unique: Tv7QDNYrROOd3PH-KZuHnA-49 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Yes, the last one, output/3-flattened-merged-A.pdf is missing field values. -----Original Message----- From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de]=20 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 : >=20 > 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 R= eader XI (11.0.12) I see a popup saying "Out of Memory". > That popup usually appears after scrolling down the merged document. >=20 > 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 >=20 > The following code loads and populates the documents and then flattens an= d merges them. > Whether or not the flatten() is called does not make a difference. =20 > If someone can have a look, I'd really appreciate it. >=20 > import java.io.File; > import java.util.Date; >=20 > 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; >=20 > public class PDFBoxRun { >=20 > public static void main(String[] args) { >=20 > System.out.println("Running..."); > PDDocument pdDocumentA =3D null; > PDDocument pdDocumentB =3D null; > PDDocument pdDocumentC =3D null; > PDDocument pdDocumentD =3D null; >=20 > try { >=20 > pdDocumentA =3D PDDocument.load(new File("template/EndFaxCover_CA.pd= f")); > PDAcroForm acroForm =3D 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 MAJOR1= 23 AUTO INS SVCS, INC"); > ((PDTextField) acroForm.getField("quoteNum")).setValue("2917812"); >=20 > pdDocumentB =3D PDDocument.load(new File("template/EndDetails_CA.pdf= ")); > acroForm =3D 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 MAJOR1= 23 AUTO INS SVCS, INC (998888)"); > ((PDTextField) acroForm.getField("hInsName")).setValue("EXAMPLE N SU= REDNAME"); > ((PDTextField) acroForm.getField("BIPDLim")).setValue("$15,000/$30,0= 00/$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"); >=20 > pdDocumentC =3D PDDocument.load(new File("template/EndSig_CA.pdf")); > acroForm =3D 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 MAJOR1= 23 AUTO INS SVCS, INC (998888)"); > ((PDTextField) acroForm.getField("hInsName")).setValue("EXAMPLE N SU= REDNAME"); > ((PDTextField) acroForm.getField("umpdRejSigAppl")).setValue("XXXX")= ; >=20 > pdDocumentD =3D PDDocument.load(new File("template/EndExclDrv_CA.pdf= ")); > acroForm =3D 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 SU= REDNAME"); > ((PDTextField) acroForm.getField("polnum")).setValue("[22-CA-116850A= (quote 2917812)"); > ((PDTextField) acroForm.getField("agencyDesc")).setValue("THE MAJOR1= 23 AUTO INS SVCS, INC (998888)"); >=20 > 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"); >=20 > pdDocumentA.getDocumentCatalog().getAcroForm().flatten(); > pdDocumentB.getDocumentCatalog().getAcroForm().flatten(); > pdDocumentC.getDocumentCatalog().getAcroForm().flatten(); > pdDocumentD.getDocumentCatalog().getAcroForm().flatten(); >=20 > 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"); >=20 > System.out.println("Merging..."); > PDFMergerUtility mergerUtility =3D new PDFMergerUtility(); > mergerUtility.appendDocument(pdDocumentA, pdDocumentB); > mergerUtility.appendDocument(pdDocumentA, pdDocumentC); > mergerUtility.appendDocument(pdDocumentA, pdDocumentD); > System.out.println("Saving merged document as output/3-flattened-mer= ged-A.pdf"); > pdDocumentA.save("output/3-flattened-merged-A.pdf"); >=20 > System.out.println("Done."); > } catch (Exception ex) { > System.err.println("Caught " + ex); > ex.printStackTrace(); > } finally { > close(pdDocumentA); > close(pdDocumentB); > close(pdDocumentC); > close(pdDocumentD); > } > } >=20 > static void close(PDDocument doc) { > if (null !=3D doc) { > try { doc.close(); } catch (Exception ex) { } > } > } >=20 > } --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org For additional commands, e-mail: users-help@pdfbox.apache.org