pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vadim Bauer <bauer.va...@gmail.com>
Subject Workaround for PDFBOX-2893
Date Fri, 18 Sep 2015 17:40:30 GMT

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 <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,
         BadFieldValueException {
      Calendar now = Calendar.getInstance();
      PDDocumentCatalog catalog = doc.getDocumentCatalog();

      PDMetadata metadata = new PDMetadata(doc);

new XmpSerializer().serialize(xmp, metadata.createOutputStream(), true);

View raw message