[
https://issues.apache.org/jira/browse/PDFBOX-2803?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
John Hewson resolved PDFBOX-2803.
---------------------------------
Resolution: Fixed
Fix Version/s: 2.0.0
Thanks for reporting this, however the constructor PDType0Font(COSDictionary
fontDictionary) is for reading existing fonts from PDF files, not for embedding
new fonts, so this constructor should not create an embedder object as occurs
in your workaround.
I've fixed the NPE by making willBeSubset() first check that the embedder is
non-null:
{code}
@Override
public boolean willBeSubset()
{
return embedder != null && embedder.needsSubset();
}
{code}
> NullPointerException into class PDType0Font
> -------------------------------------------
>
> Key: PDFBOX-2803
> URL: https://issues.apache.org/jira/browse/PDFBOX-2803
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.0
> Reporter: Konstantin Kakunin
> Assignee: John Hewson
> Fix For: 2.0.0
>
> Attachments: help-email.zip
>
>
> I find error on trunk (from 12 May 2015 )
> {code}
> Exception in thread "main" java.lang.NullPointerException
> at
> org.apache.pdfbox.pdmodel.font.PDType0Font.willBeSubset(PDType0Font.java:150)
> at
> org.apache.pdfbox.pdmodel.PDPageContentStream.setFont(PDPageContentStream.java:304)
> at
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:295)
> at
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.createAppearanceContent(AppearanceGeneratorHelper.java:227)
> at
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:202)
> at
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGenerator.generateFieldAppearances(AppearanceGenerator.java:61)
> at
> org.apache.pdfbox.pdmodel.interactive.form.PDField.updateFieldAppearances(PDField.java:110)
> at
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:286)
> at pdftext.my_main.main(my_main.java:74)
> {code}
> For me, I fixed error as:
> {code}
> /**
> * Constructor for reading a Type0 font from a PDF file.
> *
> * @param fontDictionary The font dictionary according to the PDF
> specification.
> */
> public PDType0Font(COSDictionary fontDictionary) throws IOException
> {
> super(fontDictionary);
> COSArray descendantFonts =
> (COSArray)dict.getDictionaryObject(COSName.DESCENDANT_FONTS);
> COSDictionary descendantFontDictionary = (COSDictionary)
> descendantFonts.getObject(0);
> if (descendantFontDictionary == null)
> {
> throw new IOException("Missing descendant font dictionary");
> }
> descendantFont =
> PDFontFactory.createDescendantFont(descendantFontDictionary, this);
> readEncoding();
> fetchCMapUCS2();
>
> //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> PDType0Font parentFont = PDType0Font.load(new PDDocument(), new
> File("c:\\Windows\\Fonts\\arial.ttf")); //kostya!!!!
> embedder = parentFont.embedder; //kostya!!!!
> }
> {code}
> embedder has not been initialized in
> {code}
> public PDType0Font(COSDictionary fontDictionary) throws IOException
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]