You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by sk...@gmail.com on 2015/07/24 16:46:06 UTC

ClassCastException at PDFParser:667 (PDFBox 1.8.10)

I'm using PDFMergerUtility to merge a number of PDF input streams and write
them to an HTTP response output stream.  One of the PDFs is failing at line
667 in PDFParser:

    final COSName objectType = (COSName)strmObj.getItem( COSName.TYPE );

The result of getItem(COSName.TYPE) is a COSString (value "Metadata") and
not a COSName.

I have patched this locally by changing the code to the following:

    COSBase baseObject = (COSBase)strmObj.getItem( COSName.TYPE );

    COSName objectType = null;

    if (baseObject instanceof COSString) {

        String baseObjectValue = ((COSString)baseObject).getString();

        objectType = COSName.getPDFName(baseObjectValue);

    }

    else

    {

        objectType = (COSName)baseObject;

    }
With this change, I am able to merge my PDF input streams without error.

Does this seem like an acceptable change (that should be submitted as a
patch) or am I missing something?  The PDFs being merged are viewable by
Chrome's internal PDF viewer as well as OSX Preview, Adobe Reader and
Bluebeam Vu/Revu.

Thanks!

Re: ClassCastException at PDFParser:667 (PDFBox 1.8.10)

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

I'd replace this lines

                     final COSName objectType = 
(COSName)strmObj.getItem( COSName.TYPE );
                     if( objectType != null && objectType.equals( 
COSName.XREF ) )

by this line:

if (COSName.XREF.equals(strmObj.getItem(COSName.TYPE)))


Can you share the file? If yes, please attach the file to this issue, or 
upload it to a public place and I'll attach it myself if you don't want 
to register.

https://issues.apache.org/jira/browse/PDFBOX-2903

Tilman

Am 24.07.2015 um 16:46 schrieb skenny@gmail.com:
> I'm using PDFMergerUtility to merge a number of PDF input streams and write
> them to an HTTP response output stream.  One of the PDFs is failing at line
> 667 in PDFParser:
>
>      final COSName objectType = (COSName)strmObj.getItem( COSName.TYPE );
>
> The result of getItem(COSName.TYPE) is a COSString (value "Metadata") and
> not a COSName.
>
> I have patched this locally by changing the code to the following:
>
>      COSBase baseObject = (COSBase)strmObj.getItem( COSName.TYPE );
>
>      COSName objectType = null;
>
>      if (baseObject instanceof COSString) {
>
>          String baseObjectValue = ((COSString)baseObject).getString();
>
>          objectType = COSName.getPDFName(baseObjectValue);
>
>      }
>
>      else
>
>      {
>
>          objectType = (COSName)baseObject;
>
>      }
> With this change, I am able to merge my PDF input streams without error.
>
> Does this seem like an acceptable change (that should be submitted as a
> patch) or am I missing something?  The PDFs being merged are viewable by
> Chrome's internal PDF viewer as well as OSX Preview, Adobe Reader and
> Bluebeam Vu/Revu.
>
> Thanks!
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org