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 5168318464 for ; Sun, 20 Sep 2015 15:17:37 +0000 (UTC) Received: (qmail 63344 invoked by uid 500); 20 Sep 2015 15:17:37 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 63320 invoked by uid 500); 20 Sep 2015 15:17:36 -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 63305 invoked by uid 99); 20 Sep 2015 15:17:36 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Sep 2015 15:17:36 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 42AABC0CDC for ; Sun, 20 Sep 2015 15:17:36 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.975 X-Spam-Level: X-Spam-Status: No, score=0.975 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.006, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id V91gifQrRxyv for ; Sun, 20 Sep 2015 15:17:28 +0000 (UTC) Received: from mailout08.t-online.de (mailout08.t-online.de [194.25.134.20]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id DD96942F38 for ; Sun, 20 Sep 2015 15:17:27 +0000 (UTC) Received: from fwd17.aul.t-online.de (fwd17.aul.t-online.de [172.20.27.64]) by mailout08.t-online.de (Postfix) with SMTP id 0501933E565 for ; Sun, 20 Sep 2015 17:17:20 +0200 (CEST) Received: from [192.168.2.102] (bHhPBiZLohYruX6v5zeAqbmpRRPfUIWqiz31-1Ukozl-WyrZVJJHX+Yl54+E97QgEF@[217.231.133.146]) by fwd17.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-SHA encrypted) esmtp id 1ZdgMW-2A18pk0; Sun, 20 Sep 2015 17:17:08 +0200 Subject: Re: Workaround for PDFBOX-2893 To: users@pdfbox.apache.org References: <2ECDA00F-FCCC-499D-86A0-A403F2182403@gmail.com> <55FC51E8.1030100@t-online.de> From: Tilman Hausherr Message-ID: <55FECE06.2000809@t-online.de> Date: Sun, 20 Sep 2015 17:17:26 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-ID: bHhPBiZLohYruX6v5zeAqbmpRRPfUIWqiz31-1Ukozl-WyrZVJJHX+Yl54+E97QgEF X-TOI-MSGID: 950b3366-ad2f-477c-845d-6bfcd1c06cb7 You didn't close your meta output Stream. Your code works if you do this: OutputStream osMeta = metadata.createOutputStream(); new XmpSerializer().serialize(xmp, osMeta, true); osMeta.close(); Tilman Am 20.09.2015 um 15:44 schrieb Vadim Bauer: > Hello, > > I created a minimal test cases that causes the IllegalStateException: "Cannot read while there is an open stream writer" error. > > https://issues.apache.org/jira/browse/PDFBOX-2977 > > Testcase > https://gist.github.com/Vad1mo/767f52a46e229dcaa5a6 > > > >> Am 18.09.2015 um 20:03 schrieb Tilman Hausherr : >> >> PDFBOX-2893 is mostly done, it was already set to resolved until I found a problem with merging, which has been solved. What remains are finding useful names, which John wanted to do. >> >> So I'd suggest you open a new issue, and attach a minimal but fully-working test case. >> >> Tilman >> >> Am 18.09.2015 um 19:40 schrieb Vadim Bauer: >>> Hello, >>> >>> >>> we get this stacktrace when saving modified PDFs: >>> Caused by: java.lang.IllegalStateException: Cannot read while there is an open stream writer >>> at org.apache.pdfbox.cos.COSStream.createRawInputStream(COSStream.java:128) >>> at org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:1138) >>> at org.apache.pdfbox.cos.COSStream.accept(COSStream.java:369) >>> at org.apache.pdfbox.pdfwriter.COSWriter.doWriteObject(COSWriter.java:538) >>> at org.apache.pdfbox.pdfwriter.COSWriter.doWriteBody(COSWriter.java:450) >>> at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1039) >>> at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:445) >>> at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1289) >>> at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1190) >>> at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1212) >>> >>> There is already an issue in jira but since july it is still WIP in progress so we are looking for a workaround until the issue is fixed. >>> https://issues.apache.org/jira/browse/PDFBOX-2893 >>> >>> What we are actually doing is attaching a file to pdf and save it under a new name. >>> >>> The error occurs in our case when we set the metadata: >>> *private* *void* setMetadata(PDDocument doc, AppendParameter appendParameter) *throws* IOException, TransformerException, >>> BadFieldValueException { >>> Calendar now = Calendar.getInstance(); >>> PDDocumentCatalog catalog = doc.getDocumentCatalog(); >>> >>> PDMetadata metadata = *new* PDMetadata(doc); >>> //catalog.setMetadata(metadata); >>> >>> *new* XmpSerializer().serialize(xmp, metadata.createOutputStream(), *true*); >>> --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org For additional commands, e-mail: users-help@pdfbox.apache.org