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 2014/08/19 18:23:19 UTC

[jira] [Comment Edited] (PDFBOX-2275) ClassCastException in PDResources

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

Tilman Hausherr edited comment on PDFBOX-2275 at 8/19/14 4:22 PM:
------------------------------------------------------------------

[~dnt] please change the code segment in PDResources to this and test your application:

{code}
try
{
    String name = objName.getName();
    COSBase item = dict.getItem(objName);
    if (item instanceof COSObject)
    {
        COSObject cosObject = (COSObject) item;
        // add the object number to create an unique identifier
        name += "#" + cosObject.getObjectNumber().intValue();
        xobject = PDXObject.createXObject(cosObject.getObject(), name, this);
    }
    else
    if (item instanceof COSBase)
    {
        xobject = PDXObject.createXObject(item, name, this);
    }
}
{code}

I think the problem is that you're calling the method at a time where the objects are already prepared (but not the xobjects map), while the original intent was to use it at a time the objects were known only by their reference number (look into a PDF with an editor to see what I mean). My change takes care of this difference. 

[~lehmi] WDYT? Patch proposal attached.



was (Author: tilman):
[~dnt] please change the code segment to this and test your application:

{code}
try
{
    String name = objName.getName();
    COSBase item = dict.getItem(objName);
    if (item instanceof COSObject)
    {
        COSObject cosObject = (COSObject) item;
        // add the object number to create an unique identifier
        name += "#" + cosObject.getObjectNumber().intValue();
        xobject = PDXObject.createXObject(cosObject.getObject(), name, this);
    }
    else
    if (item instanceof COSBase)
    {
        xobject = PDXObject.createXObject(item, name, this);
    }
}
{code}

I think the problem is that you're calling the method at a time where the objects are already prepared (but not the xobjects map), while the original intent was to use it at a time the objects were known only by their reference number (look into a PDF with an editor to see what I mean). My change takes care of this difference. 

[~lehmi] WDYT? Patch proposal attached.


> 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
>         Attachments: PDResources.diff
>
>
> 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)