You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "jerome girardini (JIRA)" <ji...@apache.org> on 2015/04/01 09:31:53 UTC

[jira] [Created] (PDFBOX-2739) Saving merged documents causes IOException

jerome girardini created PDFBOX-2739:
----------------------------------------

             Summary: Saving merged documents causes IOException
                 Key: PDFBOX-2739
                 URL: https://issues.apache.org/jira/browse/PDFBOX-2739
             Project: PDFBox
          Issue Type: Bug
          Components: Writing
    Affects Versions: 2.0.0
         Environment: windows 7
            Reporter: jerome girardini


When some documents are used within a merge, it is not more possible to save the resulting PDDocument, calling method  PDDocument.save() throws "java.io.IOException: COSStream has been closed and cannot be read. Perhaps its enclosing PDDocument has been closed?"

{code:borderStyle=solid}
Exception in thread "main" java.io.IOException: COSStream has been closed and cannot be read. Perhaps its enclosing PDDocument has been closed?
	at org.apache.pdfbox.cos.COSStream.getFilteredStream(COSStream.java:163)
	at org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:1147)
	at org.apache.pdfbox.cos.COSStream.accept(COSStream.java:280)
	at org.apache.pdfbox.cos.COSObject.accept(COSObject.java:158)
	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:1031)
	at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:464)
	at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1307)
	at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1215)
	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:944)
	at ch.ge.afc.ael.commun.piecejointe.Test.main(Test.java:37)
{code}

For instance, problem occures with testPopupAnnotation.pdf when I try to merge it to testPDF.pdf  (see  http://svn.apache.org/repos/asf/tika/trunk/tika-parsers/src/test/resources/test-documents/  for these 2 documents)

{code:title=Test.java|borderStyle=solid}
public static void main(String[] args) throws Exception {
	File dir = new File("D:/temp/b");

	PDFMergerUtility pdfMerge = new PDFMergerUtility();
	PDDocument targetDocument = new PDDocument();


	PDFParser ns = new PDFParser(new File(dir, "testPDF.pdf"));
	ns.parse();
	PDDocument pddDocument1 = ns.getPDDocument();
	pdfMerge.appendDocument(targetDocument, pddDocument1);
	pddDocument1.close();

	ns = new PDFParser(new File(dir, "testPopupAnnotation.pdf"));
	ns.parse();
	PDDocument pddDocument2 = ns.getPDDocument();
	pdfMerge.appendDocument(targetDocument, pddDocument2);
	pddDocument2.close();

	pdfMerge.mergeDocuments();

	FileOutputStream fout = new FileOutputStream(new File(dir, "targetDocument.pdf"));
	targetDocument.save(fout);

}

{code}






--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org