You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Andreas Lehmkühler <an...@lehmi.de> on 2009/07/03 16:53:18 UTC
Re: Possible Bug in org.apache.pdfbox.cos.COSDictionary#getNameAsString(
COSName key )
Hi Michael,
this issue was already described in [1] and the svn-version 790931
resolves that issue.
Thanks for your help.
Andreas Lehmkühler
[1] https://issues.apache.org/jira/browse/PDFBOX-455
Michael Weller schrieb:
> Hey Pdfbox-Users,
>
> I'm using Pdfbox for a custom pdf library. I'm using the TextStripper
> class to extract textual contents of the pdf's pages. This works for
> alsmost 99% of my pdfs. Here's the old implementation:
> <code>
> public String getNameAsString( COSName key )
> {
> String retval = null;
> COSName name = (COSName)getDictionaryObject( key );
> if( name != null )
> {
> retval = name.getName();
> }
> return retval;
> }
> </code>
> But for some I got ClassCastExceptions in
> COSDictionary#getNameAsString(COSName key) (used by TextStripper ..)
> because something returned by getDictionaryObject(COSName key) is not
> a COSName. After adding an "instanceof"-test I sometimes got
> NullPointerExceptions. So here is a new implementation with some
> simple checks which works for 100% of my pdfs ;-)
>
> public String getNameAsString( COSName key )
> {
> String retval = null;
>
> COSBase cb = getDictionaryObject( key );
> if (cb != null) {
> if (cb instanceof COSName) {
> COSName name = (COSName)cb;
> if( name != null )
> {
> retval = name.getName();
> }
> } else {
> retval = cb.toString();
> }
> }
> return retval;
> }
>
> As far as I can tell there are no semantics touched by these modifications.
>
> Thanks for your attention!