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 2F0D51082F for ; Fri, 8 Nov 2013 19:42:14 +0000 (UTC) Received: (qmail 24171 invoked by uid 500); 8 Nov 2013 19:42:13 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 24137 invoked by uid 500); 8 Nov 2013 19:42:13 -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 24129 invoked by uid 99); 8 Nov 2013 19:42:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Nov 2013 19:42:13 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [213.133.104.168] (HELO www168.your-server.de) (213.133.104.168) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Nov 2013 19:42:07 +0000 Received: from [78.46.5.204] (helo=sslproxy02.your-server.de) by www168.your-server.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.80.1) (envelope-from ) id 1Verw9-0003gX-5r for users@pdfbox.apache.org; Fri, 08 Nov 2013 20:41:45 +0100 Received: from [80.187.100.90] (helo=[10.143.51.217]) by sslproxy02.your-server.de with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1Verw5-00031q-Dd for users@pdfbox.apache.org; Fri, 08 Nov 2013 20:41:42 +0100 Subject: Re: NPE when filling form References: <104AA03D-F54E-4FCB-8359-1C2261746BF5@pgt.de> From: Maruan Sahyoun Content-Type: text/plain; charset=us-ascii X-Mailer: iPhone Mail (11B511) In-Reply-To: <104AA03D-F54E-4FCB-8359-1C2261746BF5@pgt.de> Message-Id: Date: Fri, 8 Nov 2013 20:41:37 +0100 To: "users@pdfbox.apache.org" Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (1.0) X-Authenticated-Sender: sahyoun@fileaffairs.de X-Virus-Scanned: Clear (ClamAV 0.97.8/18085/Fri Nov 8 18:40:43 2013) X-Virus-Checked: Checked by ClamAV on apache.org Hi Papick, is it possible to provide the file at a public location? BR Maruan > Am 08.11.2013 um 18:47 schrieb Papick Garcia Taboada : >=20 > Hi, >=20 > I am moving from iText to PDFBox to fill out a form in a PDF document.=20 >=20 > This is mainly my code: >=20 > Resource contractResource =3D ctx.getResource("classpath:/META-INF/pdfs/co= ntract.pdf"); > PDDocument doc =3D PDDocument.load(contractResource.getInputStream()); > PDDocumentCatalog docCatalog =3D doc.getDocumentCatalog(); > PDAcroForm form =3D docCatalog.getAcroForm(); >=20 > setField(doc, "field1", field1Value); > setField(doc, "field2", field2Value); > setField(doc, "field3", field3Value); >=20 > response.setStatus(200); > response.setContentType("application/pdf"); > doc.save(response.getOutputStream()); >=20 >=20 > And the setField method populates the fields: >=20 >=20 > private void setField(PDDocument doc, String fieldName, String value) thro= ws IOException { > PDDocumentCatalog docCatalog =3D doc.getDocumentCatalog(); > PDAcroForm form =3D docCatalog.getAcroForm(); > PDField field =3D form.getField(fieldName); > if (field !=3D null) { > if (!Strings.isNullOrEmpty(value)) { > field.setValue(value); > } else { > LOG.debug("Value for {} is empty", fieldName); > } > } else { > LOG.debug("Field {} not found", fieldName); > } > } >=20 >=20 > Unfortunately, I get a NPE as soon as I try to set the field.=20 >=20 > java.lang.NullPointerException > at org.apache.pdfbox.pdmodel.interactive.form.PDAppearance.calculateFon= tSize(PDAppearance.java:558) >=20 >=20 > Any tips? >=20 > brgds, >=20 > Papick >=20 >=20 >=20