pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leonard Teo <leon...@ballistiq.com>
Subject Re: ClassCastException - cannot be cast to java.lang.Number on
Date Tue, 21 May 2013 14:32:31 GMT
Hi guys,

I am running PDFBox 1.8.1, which AFAIK is current.

The issue appears to be specific to using PDSimpleFont. When I changed to
PDTrueTypeFont and passed it an TTF file for Arial it is working, so I was
able to "fix" the issue at least for now. :)

Here is the file that is not stamping:
https://dl.dropboxusercontent.com/u/1413139/test_wont_stamp.pdf

Note that the error only happens with certain strings that you pass it.

With the source code that I have provided here:
https://gist.github.com/**leonardteo/**3b8567e7f747ef640b70<https://gist.github.com/leonardteo/3b8567e7f747ef640b70>

Pass these arguments in:
"test_wont_stamp.pdf" "out.pdf" "Prepared exclusively for [customer_name]
by American Vision. Duplication Prohibited." "Eric Hamm" "1867" "17 May
2013" "tcconthego@gmail.com"

It will cause the exception on page 4.

I changed the font to using TTF and it works:

InputStream stream = getClass().getResourceAsStream("/fonts/Arial.ttf");

PDFont font = PDTrueTypeFont.loadTTF(doc, stream);

I will remove the PDF file in a few days as it is copyright. I just wanted
to help debug this issue.

Leo




On Mon, May 20, 2013 at 6:22 AM, Andreas Lehmkuehler <andreas@lehmi.de>wrote:

> Hi,
>
> Am 17.05.2013 17:24, schrieb Leonard Teo:
>
>> Hi guys,
>>
>> I have a simple PDFBox application that takes a text string and inserts it
>> into every page of a PDF file. It is based on the
>> AddMessageToEachPage.java
>> code in the example given.
>>
>> I'm having an issue where I am getting a ClassCastException on
>> CMapParser.java:137. I can see and debug the error, but I don't know why
>> it
>> would be doing this and I'm not sure what to do.
>>
> Sounds like an old issue. Which version of PDFBox are you using? maybe
> it's a
> good idea to update to a more recent version.
>
>  Here is the source code:
>
>> https://gist.github.com/**leonardteo/**3b8567e7f747ef640b70<https://gist.github.com/leonardteo/3b8567e7f747ef640b70>
>>
>> The error is happening on line 93:
>>
>> contentStream.setFont( font, fontSize );
>>
>>
>> It works on many PDF's but there are enough of these errors that it is
>> causing problems with our users.
>>
>> Any ideas what I'm doing wrong?
>>
>> Thanks,
>>
>> Leo
>>
>>
>> java.lang.ClassCastException:
>> org.apache.fontbox.cmap.**CMapParser$Operator cannot be cast to
>> java.lang.Number
>>         at org.apache.fontbox.cmap.**CMapParser.parse(CMapParser.**
>> java:137)
>>         at org.apache.pdfbox.pdmodel.**font.PDFont.parseCmap(PDFont.**
>> java:602)
>>         at org.apache.pdfbox.pdmodel.**font.PDSimpleFont.**
>> extractToUnicodeEncoding(**PDSimpleFont.java:454)
>>         at org.apache.pdfbox.pdmodel.**font.PDSimpleFont.**
>> determineEncoding(**PDSimpleFont.java:422)
>>         at org.apache.pdfbox.pdmodel.**font.PDType1Font.**
>> determineEncoding(PDType1Font.**java:269)
>>         at org.apache.pdfbox.pdmodel.**font.PDFont.<init>(PDFont.**
>> java:194)
>>         at org.apache.pdfbox.pdmodel.**font.PDSimpleFont.<init>(**
>> PDSimpleFont.java:84)
>>         at org.apache.pdfbox.pdmodel.**font.PDType1Font.<init>(**
>> PDType1Font.java:152)
>>         at org.apache.pdfbox.pdmodel.**font.PDFontFactory.createFont(**
>> PDFontFactory.java:88)
>>         at org.apache.pdfbox.pdmodel.**PDResources.getFonts(**
>> PDResources.java:187)
>>         at org.apache.pdfbox.pdmodel.**PDResources.addFont(**
>> PDResources.java:518)
>>         at org.apache.pdfbox.pdmodel.**edit.PDPageContentStream.**
>> setFont(PDPageContentStream.**java:308)
>>         at PDFStamper.stamp(PDFStamper.**java:96)
>>         at PDFStamper.main(PDFStamper.**java:128)
>>
>>
>
> BR
> Andreas Lehmkühler
>



-- 
Leonard Teo
Ballistiq Digital, Inc.
http://www.ballistiq.com
2001 University Street, Suite 1700
Montreal, QC H3A 2A6

Cell: 514 512 9873
Skype: leonardteo

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message