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

Alexandros Karargyris commented on PDFBOX-3287:
-----------------------------------------------

Here is the test:

public void saveImagesFromPDFToFilesTest(){
                DocumentProcessor test = new DocumentProcessor();
                try {
                        
test.saveImagesFromPDFToFiles(test.openPDFFile("\\Desktop\\Papers\\test.pdf"), 
2, "\\Desktop\\Papers\\");
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

        }

where "openPDFFile" is:

        public PDDocument openPDFFile(String filePath) {

                try {
                        File inputFile = new File(filePath);
                        PDDocument document = PDDocument.load(inputFile);

                        log.info("Successfully opened pdf created by '" + 
document.getDocumentInformation().getAuthor()
                                        + "' from file: " + inputFile);
                        return document;

                } catch (Exception e) {
                        log.error("Error! Couldn't open file.");
                        return null;

                }

        }



> COSStream has been closed and cannot be read. Perhaps its enclosing 
> PDDocument has been closed?
> -----------------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-3287
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3287
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.0
>         Environment: Windows
>            Reporter: Alexandros Karargyris
>            Priority: Critical
>
> I am using the example at 
> https://github.com/apache/pdfbox/blob/93339a0fb36c2cfd80e4837cc4c4206bf3a3877a/tools/src/test/java/org/apache/pdfbox/tools/imageio/TestImageIOUtils.java#L69
> to extract images from a PDF page and save it to a file. However I am running 
> to the following error at this line : 
> https://github.com/apache/pdfbox/blob/93339a0fb36c2cfd80e4837cc4c4206bf3a3877a/tools/src/test/java/org/apache/pdfbox/tools/imageio/TestImageIOUtils.java#L77
> ``
> COSStream has been closed and cannot be read. Perhaps its enclosing 
> PDDocument has been closed?
>       at org.apache.pdfbox.cos.COSStream.checkClosed(COSStream.java:78)
>       at org.apache.pdfbox.cos.COSStream.createInputStream(COSStream.java:156)
>       at 
> org.apache.pdfbox.pdmodel.common.PDStream.createInputStream(PDStream.java:235)
>       at 
> org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.<init>(PDImageXObject.java:147)
>       at 
> org.apache.pdfbox.pdmodel.graphics.PDXObject.createXObject(PDXObject.java:70)
>       at 
> org.apache.pdfbox.pdmodel.PDResources.getXObject(PDResources.java:385)
> ``



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

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

Reply via email to