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 DFC3811A97 for ; Fri, 1 Aug 2014 19:48:25 +0000 (UTC) Received: (qmail 91068 invoked by uid 500); 1 Aug 2014 19:48:25 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 91049 invoked by uid 500); 1 Aug 2014 19:48:25 -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 91036 invoked by uid 99); 1 Aug 2014 19:48:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Aug 2014 19:48:25 +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 (nike.apache.org: local policy) Received: from [194.25.134.17] (HELO mailout02.t-online.de) (194.25.134.17) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Aug 2014 19:48:21 +0000 Received: from fwd07.aul.t-online.de (fwd07.aul.t-online.de [172.20.27.150]) by mailout02.t-online.de (Postfix) with SMTP id 83EE92B65C1 for ; Fri, 1 Aug 2014 21:47:56 +0200 (CEST) Received: from [192.168.2.102] (XKAfkvZFZhehq6K9b1bJnKML4FyexNE4568+q7StDhwVaclokubA1SGtV6L8NkEZj8@[217.231.161.22]) by fwd07.t-online.de with (TLSv1:ECDHE-RSA-AES256-SHA encrypted) esmtp id 1XDInp-3TTk7E0; Fri, 1 Aug 2014 21:47:45 +0200 Message-ID: <53DBEEE1.3090508@t-online.de> Date: Fri, 01 Aug 2014 21:47:45 +0200 From: Tilman Hausherr User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: users@pdfbox.apache.org Subject: Re: Problems running PDFBox within a servlet container References: <53DBE577.6090501@t-online.de> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ID: XKAfkvZFZhehq6K9b1bJnKML4FyexNE4568+q7StDhwVaclokubA1SGtV6L8NkEZj8 X-TOI-MSGID: b0b36c6c-8ee8-410b-8c9f-c2e213bc6dbc X-Virus-Checked: Checked by ClamAV on apache.org Yes, that is what I mean, my text was unclear. One PDDocument may be accessed only by one thread. Tilman Am 01.08.2014 21:16, schrieb Brzrk One: > In my experience, parsing the PDF fails badly when the > PDDocument is accessed by more than one thread. > Usually in the decompression and decryption, but not exclusively. > Certainly the thread model is different btwn a standalone app and a servlet. > > > On Fri, Aug 1, 2014 at 3:07 PM, Tilman Hausherr > wrote: > >> I once got similar exceptions when trying to access the same PDF from >> several threads. See also >> >> https://pdfbox.apache.org/userguide/faq.html#threadsafe >> >> Tilman >> >> Am 01.08.2014 19:20, schrieb Jonathan Carr: >> >>> Hello all >>> >>> I've written code to take an existing PDF containing a form, populate >>> values in some of the fields, and then output the results as a new PDF. As >>> a standalone test class this works great, however as soon as put the code >>> into a servlet (I wish to serve the resulting PDF to users as a download) >>> I >>> get an error. The PDFBox-related code and PDF document being used are >>> exactly the same in both cases. >>> >>> Clearly there's a difference between the servlet and non-servlet >>> environments, but so far I've failed to find it. Does anyone have any >>> suggestions as to where I should be looking? >>> >>> I'm running OpenJDK 7 and pdfbox-1.8.6, with Jetty as my servlet >>> container. >>> >>> Example code: >>> >>> InputStream in = MyServlet.class.getResourceAsStream("Form.pdf"); >>> PDDocument doc = PDDocument.load(in); >>> PDDocumentCatalog cat = doc.getDocumentCatalog(); >>> PDAcroForm acroForm = cat.getAcroForm(); >>> >>> PDField field = acroForm.getField("myField"); >>> field.setValue("someValue"); >>> >>> >>> The following error is thrown when setValue() is called: >>> >>> java.io.IOException: null >>> at org.apache.pdfbox.filter.FlateFilter.decode(FlateFilter.java:110) >>> ~[pdfbox-app-1.8.6.jar:na] >>> at org.apache.pdfbox.cos.COSStream.doDecode(COSStream.java:342) >>> ~[pdfbox-app-1.8.6.jar:na] >>> at org.apache.pdfbox.cos.COSStream.doDecode(COSStream.java:254) >>> ~[pdfbox-app-1.8.6.jar:na] >>> at org.apache.pdfbox.cos.COSStream.getUnfilteredStream( >>> COSStream.java:188) >>> ~[pdfbox-app-1.8.6.jar:na] >>> at >>> org.apache.pdfbox.pdfparser.PDFStreamParser.( >>> PDFStreamParser.java:122) >>> ~[pdfbox-app-1.8.6.jar:na] >>> at >>> org.apache.pdfbox.pdmodel.interactive.form.PDAppearance. >>> getStreamTokens(PDAppearance.java:186) >>> ~[pdfbox-app-1.8.6.jar:na] >>> at >>> org.apache.pdfbox.pdmodel.interactive.form.PDAppearance. >>> getStreamTokens(PDAppearance.java:159) >>> ~[pdfbox-app-1.8.6.jar:na] >>> at >>> org.apache.pdfbox.pdmodel.interactive.form.PDAppearance. >>> setAppearanceValue(PDAppearance.java:266) >>> ~[pdfbox-app-1.8.6.jar:na] >>> at >>> org.apache.pdfbox.pdmodel.interactive.form.PDVariableText.setValue( >>> PDVariableText.java:131) >>> ~[pdfbox-app-1.8.6.jar:na] >>> ... >>> >>> Caused by: >>> >>> java.util.zip.DataFormatException: incorrect header check >>> at java.util.zip.Inflater.inflateBytes(Native Method) ~[na:1.7.0_55] >>> at java.util.zip.Inflater.inflate(Inflater.java:259) ~[na:1.7.0_55] >>> at java.util.zip.Inflater.inflate(Inflater.java:280) ~[na:1.7.0_55] >>> at org.apache.pdfbox.filter.FlateFilter.decompress(FlateFilter.java:129) >>> ~[pdfbox-app-1.8.6.jar:na] >>> at org.apache.pdfbox.filter.FlateFilter.decode(FlateFilter.java:102) >>> ~[pdfbox-app-1.8.6.jar:na] >>> ... >>> >>> >>> Many thanks >>> -Jonathan >>> >>>