You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2016/04/26 19:50:12 UTC

[jira] [Commented] (PDFBOX-3328) "COSStream has been closed and cannot be read" despite using importPage

    [ https://issues.apache.org/jira/browse/PDFBOX-3328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15258534#comment-15258534 ] 

Tilman Hausherr commented on PDFBOX-3328:
-----------------------------------------

I always thought that {{importPage}} does a deep copy (I even changed the javadoc not long ago in r1731095) but it doesn't, but it should. Currently it just copies the content stream (probably) and this isn't enough.

One solution would be to make {{PDFCloneUtility}} public and use it. Other ideas? It was made non public in PDFBOX-2680.

> "COSStream has been closed and cannot be read" despite using importPage
> -----------------------------------------------------------------------
>
>                 Key: PDFBOX-3328
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3328
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.0, 2.0.1, 2.1.0
>            Reporter: Tilman Hausherr
>
> By Simon G. on the user mailing list:
> {quote}
> I'm trying to copy a page from a PDF and adding it to a new (empty) document but I'm running into an issue when I close the source PDF file before I save the destination file.
> Here's a code snippet:
> {code}
>     // Load up some document from which to copy a page
>     PDDocument documentA = PDDocument.load(new File("a.pdf"));
>     // Create a new document and import the first page of the a document
>     PDDocument newDocument = new PDDocument();
>     newDocument.importPage(documentA.getPage(0));
>     // Close the A document as we don't need it any longer
>     documentA.close();
>     // Save the new document, this throws:
>     // COSStream has been closed and cannot be read. Perhaps its enclosing PDDocument has been closed?
>     // java.io.IOException: COSStream has been closed and cannot be read. Perhaps its enclosing PDDocument has been closed?
>     newDocument.save(new File("new.pdf"));
> {code}
> I get a similar exception when using the PDFMergerUtility class.
> I need to copy quite a few pages into a single output document and I'd like to avoid keeping all those source documents open both at the source and in the destination document.
> {quote}



--
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