You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "A.D. Kent" <al...@gmail.com> on 2014/07/09 21:31:13 UTC

Error with PDFRenderer.renderImageWithDPI

Hello PDFBox community,

I have a working model that copies & scales PDF pages from one 
PDDocument to another (thanks Maruan), however, when I attempt to 
convert the target document to an image via PDFRenderer, I am getting 
the following error:

    SEVERE: Error converting PDF to TIFF:
    org.apache.pdfbox.cos.COSStream cannot be cast to
    org.apache.pdfbox.cos.COSObject
    java.lang.ClassCastException: org.apache.pdfbox.cos.COSStream cannot
    be cast to org.apache.pdfbox.cos.COSObject
         at
    org.apache.pdfbox.pdmodel.PDResources.getXObjects(PDResources.java:245)

For backgrounder, I am using a PDFormXObject to copy the contents of a 
source page and place within a new page within the target document.  
This approach allows me to scale the object down, allowing for more 
margin to accommodate OMR marks.  Some brief code:

    PDPageContentStream contentStream = new
    PDPageContentStream(targetDoc, targetPage, false, false);
    contentStream.drawXObject(form, (mediaBox.getWidth() -
    mediaBox.getWidth()*scale)/2,(mediaBox.getHeight()
    -mediaBox.getHeight()*scale)/2,mediaBox.getWidth()*scale,mediaBox.getHeight()*scale);
      contentStream.close();

    return targetDoc;


If I save the targetDoc to disk, then load into a new PDDocument, I do 
not get this error.  However, if I simply attempt to render the 
targetDoc to an image, I get the stacktrace above.

Please advise.


A.D. Kent