You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Emanuel Greisen (JIRA)" <ji...@apache.org> on 2016/09/27 15:46:20 UTC
[jira] [Commented] (PDFBOX-3513) PDFType3Font can have Encoding
which is not a COSDictionary
[ https://issues.apache.org/jira/browse/PDFBOX-3513?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15526516#comment-15526516 ]
Emanuel Greisen commented on PDFBOX-3513:
-----------------------------------------
This is not pretty, but it works for the PDF I have:
*org.apache.pdfbox.pdmodel.font.PDType3Font*
{code}
@Override
protected final void readEncoding() throws IOException
{
COSBase obj = dict.getDictionaryObject(COSName.ENCODING);
if(obj instanceof COSDictionary)
{
COSDictionary encodingDict = (COSDictionary)obj;
encoding = new DictionaryEncoding(encodingDict);
}
else if(obj instanceof COSName)
{
COSName encName = (COSName) obj;
if("WinAnsiEncoding".equals(encName.getName()))
{
encoding = new WinAnsiEncoding();
}
else
{
throw new UnsupportedOperationException("unsupported Type 3 encoding: "+encName.getName());
}
}
else
{
throw new UnsupportedOperationException("unknown object stored as encoding");
}
glyphList = GlyphList.getAdobeGlyphList();
}
{code}
> 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: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org