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 0F5F41765A for ; Thu, 30 Apr 2015 09:37:36 +0000 (UTC) Received: (qmail 5543 invoked by uid 500); 30 Apr 2015 09:37:35 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 5518 invoked by uid 500); 30 Apr 2015 09:37:35 -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 5504 invoked by uid 99); 30 Apr 2015 09:37:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Apr 2015 09:37:35 +0000 X-ASF-Spam-Status: No, hits=0.0 required=5.0 tests= X-Spam-Check-By: apache.org Received-SPF: error (nike.apache.org: local policy) Received: from [54.76.25.247] (HELO mx1-eu-west.apache.org) (54.76.25.247) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Apr 2015 09:37:08 +0000 Received: from www168.your-server.de (www168.your-server.de [213.133.104.168]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 5B3F12D179 for ; Thu, 30 Apr 2015 09:36:47 +0000 (UTC) Received: from [88.198.220.130] (helo=sslproxy01.your-server.de) by www168.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.80.1) (envelope-from ) id 1YnktY-0005R0-Ri for users@pdfbox.apache.org; Thu, 30 Apr 2015 11:36:36 +0200 Received: from [79.242.114.97] (helo=mbp001.intern) by sslproxy01.your-server.de with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.80) (envelope-from ) id 1YnktV-0005gV-GZ for users@pdfbox.apache.org; Thu, 30 Apr 2015 11:36:33 +0200 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) Subject: Re: "Empty" AcroFields From: Maruan Sahyoun In-Reply-To: <976387179.923230155.1430386262257.JavaMail.root@zimbra65-e11.priv.proxad.net> Date: Thu, 30 Apr 2015 11:36:29 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: References: <976387179.923230155.1430386262257.JavaMail.root@zimbra65-e11.priv.proxad.net> To: users@pdfbox.apache.org X-Mailer: Apple Mail (2.2098) X-Authenticated-Sender: sahyoun@fileaffairs.de X-Virus-Scanned: Clear (ClamAV 0.98.5/20396/Thu Apr 30 06:37:10 2015) X-Virus-Checked: Checked by ClamAV on apache.org Hi, > Am 30.04.2015 um 11:31 schrieb phiroc@free.fr: >=20 >=20 > Hello, >=20 > I have solved my problems by re-creating my template from scratch with = OpenOffice and exporting it to PDF, instead of using a template created = by one of my colleagues using an MS Word file which he imported into = Acrobat Pro. >=20 > Case closed. >=20 thanks Philippe for letting us know - I was just about to take a look at = your files. Good luck with your project. Maruan > Philippe >=20 >=20 > ----- Mail original ----- > De: phiroc@free.fr > =C3=80: users@pdfbox.apache.org > Envoy=C3=A9: Lundi 27 Avril 2015 14:15:56 > Objet: Re: "Empty" AcroFields >=20 > Hi Maruan, >=20 > I've printed one of the generated PDFs and some of the fields contain = vertical text. >=20 > Best regards, >=20 > Philippe >=20 > ----- Mail original ----- > De: phiroc@free.fr > =C3=80: users@pdfbox.apache.org > Envoy=C3=A9: Lundi 27 Avril 2015 13:46:45 > Objet: Re: "Empty" AcroFields >=20 > Hi Maruan, >=20 > I am using version 1.8.9. >=20 > Yes, I can provide the empty sample and a filled-out form. >=20 > May I send them to your e-mail address? >=20 > Thanks. >=20 > Philippe >=20 >=20 >=20 > ----- Mail original ----- > De: "Maruan Sahyoun" > =C3=80: users@pdfbox.apache.org > Envoy=C3=A9: Lundi 27 Avril 2015 12:40:04 > Objet: Re: "Empty" AcroFields >=20 > Hi >=20 >> Am 27.04.2015 um 12:32 schrieb phiroc@free.fr: >>=20 >> Hello, >>=20 >>=20 >> the following code creates a PDF whose pages contain AcroForms filled = in with data extracted from a CSV file. >> The forms' template was created with Acrobat Pro. It is landscaped = (+90 degree rotation). >>=20 >> I have the following issues: >>=20 >> - when I open each generated form in Acrobat, the fields look empty = or contain text which is lightly offset to the left and top (for = instance, you can only see the text's bottom). >> If I click an "empty" field though, its contents appear. >> - if I set the form's fields to read-only in my code, the text = appears, but it is vertical >=20 > this behavior means that the appearance might not have been generated = correctly. Which version of PDFBox are you using? Would you have an = empty sample form, and the same filled with Acrobat and PDFBox? >=20 > Sidenote - although it's defined in the PDF specification how an = appearance is generated the 'styling' (such a padding around the text, = linespacing...) is not part of the PDF specification so one can only = replicate the behavior of e.g. Acrobat. Your form might still look = different (or OK) using a different reader. >=20 > BR > Maruan >=20 >>=20 >> How can I fix these issues? >>=20 >> Many thanks. >>=20 >> Philippe >>=20 >>=20 >> void generatePdf(final List> = csvDataArrayList, final File pdfTemplateFilePath, >> final String pathToGeneratedPdfDirectory) >> throws COSVisitorException, = IOException { >>=20 >> final File finalDocFilePath =3D new = File(pathToGeneratedPdfDirectory, "newPdf.pdf"); >>=20 >> final PDDocument finalDoc =3D new PDDocument(); >> final List finalDocFields =3D new = ArrayList(); >>=20 >> int csvLineCounter =3D 0; >>=20 >> // Loop through CSV lines and retrieve each line's data >> for (Map pdfLineTreeMap : = csvDataArrayList) { >>=20 >> // Retrieve template's catalog >> final PDDocumentCatalog templateCatalog =3D = PDDocument.load(pdfTemplateFilePath).getDocumentCatalog(); >> // Retrieve its acroForm >> final PDAcroForm templateAcroForm =3D = templateCatalog.getAcroForm(); >>=20 >> // Get all template PDF's pages >> final List templateCatalogPages =3D = templateCatalog.getAllPages(); >> // Get template document's first page >> final PDPage templateFirstPage =3D = templateCatalogPages.get(0); >>=20 >> // Add first page to final doc with filled out = fields >> finalDoc.addPage(templateFirstPage); >>=20 >> // Loop through PDF field names in = pdfLineTreeMap (this map was previously >> // created to store the CSV data; its keys are = equal to the >> // PDF field names) and set their respective = values in PDF >> for (String fieldName : pdfLineTreeMap.keySet()) = { >>=20 >> final String fieldValue =3D = pdfLineTreeMap.get(fieldName); >> // Try to retrieve the field in the = template's acroForm with the same name >> // as the column in csvDataArrayList >> final PDField pDField =3D = templateAcroForm.getField(fieldName); >>=20 >> // field with same name in CSV as in PDF = was found... >> if (pDField !=3D null) { >>=20 >> // Only circle non-empty = insertion codes >> if (fieldName.indexOf("INSERT") = >=3D 0 && fieldValue !=3D null && fieldValue.length() > 0) { >> circleField(pDField, = templateFirstPage); >> } >> // add increment to it's partial = name >> pDField.setPartialName(fieldName = + Integer.toString(csvLineCounter)); >> pDField.setValue(fieldValue); >> //pDField.setReadonly(true); >>=20 >> finalDocFields.add(pDField); >> } >>=20 >> } // end for fieldName >>=20 >> // Page number is in templateAcroForm (but not = in pdfLineTreeMap) >> final PDField pDPageField =3D = templateAcroForm.getField("pagenumber"); >> if (pDPageField !=3D null) { >> pDPageField.setPartialName("pagenumber" = + Integer.toString(csvLineCounter)); >> = pDPageField.setValue(Integer.toString(csvLineCounter + 1)); >> //pDPageField.setReadonly(true); >> finalDocFields.add(pDPageField); >> } >>=20 >> // Stop at second CSV line for debugging !!!!! >> if (csvLineCounter =3D=3D 10) { >> break; >> } >>=20 >> ++csvLineCounter; >>=20 >> } // end for CSV Lines >>=20 >> // Create new form in final document >> final PDAcroForm finalDocAcroForm =3D new = PDAcroForm(finalDoc); >> // Set final document's form >> = finalDoc.getDocumentCatalog().setAcroForm(finalDocAcroForm); >> // Set form's fields >> finalDocAcroForm.setFields(finalDocFields); >> // Save final doc >> finalDoc.save(finalDocFilePath); >> finalDoc.close(); >>=20 >> } // end generatePdf method >>=20 >>=20 >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org >> For additional commands, e-mail: users-help@pdfbox.apache.org >>=20 >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org > For additional commands, e-mail: users-help@pdfbox.apache.org >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org > For additional commands, e-mail: users-help@pdfbox.apache.org >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org > For additional commands, e-mail: users-help@pdfbox.apache.org >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org > For additional commands, e-mail: users-help@pdfbox.apache.org >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org For additional commands, e-mail: users-help@pdfbox.apache.org