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 <[email protected]>:
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: [email protected]
For additional commands, e-mail: [email protected]