[ https://issues.apache.org/jira/browse/PDFBOX-2275?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14100927#comment-14100927 ]
Tilman Hausherr commented on PDFBOX-2275: ----------------------------------------- I haven't understood the problem: does the exception (of which you didn't include the details) happen when creating or when opening the created PDF file? If the later, I can't reproduce it. I modified the code of ValidateXImage (search for "loadNonSeq" in that file), and I don't get an exception: {code} document = PDDocument.loadNonSeq(pdfFile, null); new PDFRenderer(document).renderImage(0); List<PDPage> pageList = document.getDocumentCatalog().getAllPages(); PDResources resources = pageList.get(0).getResources(); resources.getXObjects(); document.close(); {code} Like I said in the other issue - the best is to submit the shortest possible standalone code that fails. > ClassCastException in PDResources > --------------------------------- > > Key: PDFBOX-2275 > URL: https://issues.apache.org/jira/browse/PDFBOX-2275 > Project: PDFBox > Issue Type: Bug > Components: PDModel > Affects Versions: 2.0.0 > Reporter: Dominic Tubach > > The code (added in revision 1606860) > {code} > COSObject cosObject = (COSObject)dict.getItem(objName); > {code} in the method getXObjects() in PDResources fails with a > ClassCastException: > bq. org.apache.pdfbox.cos.COSStream cannot be cast to > org.apache.pdfbox.cos.COSObject > The document issuing this exception is created using the following code: > {code} > PDDocument doc = new PDDocument(); > PDPage page = new PDPage(); > doc.addPage(page); > PDImageXObject image = JPEGFactory.createFromStream(doc, imageStream); > try (PDPageContentStream contentStream = new PDPageContentStream(doc, page, > false, false)) { > contentStream.drawImage(image, 20, 20); > } > {code} -- This message was sent by Atlassian JIRA (v6.2#6252)