[
https://issues.apache.org/jira/browse/PDFBOX-3513?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15527538#comment-15527538
]
John Hewson commented on PDFBOX-3513:
-------------------------------------
Indeed, Type 3 fonts are required to have an encoding dictionary. But the spec
has nothing to say on what to do when that is not the case. For non-Type 3
fonts the fallback encoding is StandardEncoding, and I suspect that this is
being used, not WinAnsiEncoding. Alternatively the font could be completely
disregarded.
[~emanuelgreisen], try this instead:
{code}
encoding = new DictionaryEncoding(new COSDictionary());
{code}
Does the text extraction produce the same result?
> PDFType3Font can have Encoding which is not a COSDictionary
> -----------------------------------------------------------
>
> Key: PDFBOX-3513
> URL: https://issues.apache.org/jira/browse/PDFBOX-3513
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 2.0.3
> Reporter: Emanuel Greisen
>
> I tried the "ExtractTextByArea" with a PDF from my bank and go the following
> stacktrace:
> {code}
> Exception in thread "main" java.lang.ClassCastException:
> org.apache.pdfbox.cos.COSName cannot be cast to
> org.apache.pdfbox.cos.COSDictionary
> at
> org.apache.pdfbox.pdmodel.font.PDType3Font.readEncoding(PDType3Font.java:70)
> at
> org.apache.pdfbox.pdmodel.font.PDType3Font.<init>(PDType3Font.java:57)
> at
> org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:79)
> at org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:143)
> at
> org.apache.pdfbox.contentstream.operator.text.SetFontAndSize.process(SetFontAndSize.java:60)
> at
> org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:815)
> at
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:472)
> at
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:446)
> at
> org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:149)
> at
> org.apache.pdfbox.text.LegacyPDFStreamEngine.processPage(LegacyPDFStreamEngine.java:139)
> at
> org.apache.pdfbox.text.PDFTextStripper.processPage(PDFTextStripper.java:391)
> at
> org.apache.pdfbox.text.PDFTextStripperByArea.extractRegions(PDFTextStripperByArea.java:130)
> {code}
> I can read the PDF with evince, pdftk, lesspipe to extract text. I cannot
> upload the file as it is a bank statement with content I will not share.
> Debugging the application I found that the return from PDType3Font.java:69
> {code}
> dict.getDictionaryObject(COSName.ENCODING)
> {code}
> Is an object of type: "COSName" with the name property set to
> "WinAnsiEncoding".
> I hope this helps - despite the fact that I cannot share the example PDF.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]