[ 
https://issues.apache.org/jira/browse/PDFBOX-3901?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tilman Hausherr closed PDFBOX-3901.
-----------------------------------
    Resolution: Won't Fix

Closing as won't fix. This is partly by design and partly a possible bug, but 
which I can't investigate without the files. The workaround (merge in small 
steps) is easy IMHO, i.e. less than a day of work.


> Merging PDF error: COSStream has been closed and cannot be read. Perhaps its 
> enclosing PDDocument has been closed
> -----------------------------------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-3901
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3901
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.0.4, 2.0.7
>            Reporter: Wei Zhang
>
> I am trying to merge around 2500 pdfs to one file. But I got the error below.
> Caused by: java.io.IOException: COSStream has been closed and cannot be read. 
> Perhaps its enclosing PDDocument has been closed?
> at org.apache.pdfbox.cos.COSStream.checkClosed(COSStream.java:77) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.cos.COSStream.createRawInputStream(COSStream.java:125) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:1200) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.cos.COSStream.accept(COSStream.java:383) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.cos.COSObject.accept(COSObject.java:158) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.pdfwriter.COSWriter.doWriteObject(COSWriter.java:522) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.pdfwriter.COSWriter.doWriteObjects(COSWriter.java:460) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.pdfwriter.COSWriter.doWriteBody(COSWriter.java:444) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at 
> org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1096) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:419) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1367) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1254) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1232) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1204) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1192) 
> ~[pdfbox-2.0.4.jar:2.0.4]
> at org.apache.pdfbox.pdmodel.PDDocument$save$0.call(Unknown Source) ~[?:?]
> My code is :
> {code:title=|borderStyle=solid}
> public static void concatPdfs(List<String> sourceFiles, String dest) throws 
> IOException {
>  
>         PDFMergerUtility ut = new PDFMergerUtility();
>         PDDocument pdfDest = new 
> PDDocument(MemoryUsageSetting.setupTempFileOnly());
>         for(String source : sourceFiles) {
>             PDDocument pdfSource = PDDocument.load(new 
> FileInputStream(source), MemoryUsageSetting.setupMainMemoryOnly());
>             ut.appendDocument(pdfDest, pdfSource);
>             pdfSource.close();
>         }
>         pdfDest.save(dest);
>         pdfDest.close();
>     }
> {code}
> I was trying to find where COSStream is closed but it is difficult. Can 
> anybody help to identify the root cause? 



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to