Hi,
I am trying to open a specific font to use in a PDF document based on a font file that is on our classpath. The code I am using is as follows:
private void addCoverPage(Document packagedDoc, RiskPackageRequest request) {
Page coverPage = packagedDoc.getPages().insert(1);
TextFragment title = new TextFragment(request.getDisplayName());
title.getTextState().setFontSize(32);
// title.getTextState().setFontStyle(FontStyles.Bold);
title.getTextState().setFont(getFont());
Paragraphs paragraphs = coverPage.getParagraphs();
title.setHorizontalAlignment(HorizontalAlignment.Center);
title.setVerticalAlignment(VerticalAlignment.Center);
paragraphs.add(title);
}
private Font getFont() {
InputStream fontStream = PdfReportPackager.class.getResourceAsStream("/fonts/SegoeCondensedRegular.ttf");
LOG.info(“methodStart=inputFont, fontStream=” + fontStream);
return FontRepository.openFont(fontStream, FontTypes.TTF);
}
However when I try this I get the error below:
Note that the error occurs from the line which saves the document as opposed to when the font was used - can you advise on the options for using this font here in the pdf document
java.lang.NullPointerException
at com.aspose.pdf.TextState.m1(Unknown Source)
at com.aspose.pdf.TextState.m1(Unknown Source)
at com.aspose.pdf.TextSegment.m11(Unknown Source)
at com.aspose.pdf.TextFragmentState.setFont(Unknown Source)
at com.aspose.pdf.TextFragmentState.applyChangesFrom(Unknown Source)
at com.aspose.pdf.TextFragmentState.applyChangesFrom(Unknown Source)
at com.aspose.pdf.TextParagraph.appendLine(Unknown Source)
at com.aspose.pdf.TextParagraph.appendLine(Unknown Source)
at com.aspose.pdf.z152.m1(Unknown Source)
at com.aspose.pdf.z152.m1(Unknown Source)
at com.aspose.pdf.z152.m1(Unknown Source)
at com.aspose.pdf.z152.m8(Unknown Source)
at com.aspose.pdf.Page.m2(Unknown Source)
at com.aspose.pdf.Page.m8(Unknown Source)
at com.aspose.pdf.ADocument.processParagraphs(Unknown Source)
at com.aspose.pdf.Document.processParagraphs(Unknown Source)
at com.aspose.pdf.ADocument.saveInternal(Unknown Source)
at com.aspose.pdf.Document.saveInternal(Unknown Source)
at com.aspose.pdf.ADocument.save(Unknown Source)
at com.aspose.pdf.Document.save(Unknown Source)
at com.fmrco.risk.reporting.packager.PdfReportPackager.packageReport(PdfReportPackager.java:102)