We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Opening a specific font from a stream and saving with a pdf document


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().setFontStyle(FontStyles.Bold);
Paragraphs paragraphs = coverPage.getParagraphs();

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

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)

Hi David,

Thanks for using our API’s.

I have tested the scenario using one of my sample PDF files where I have used my sample TTF and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFJAVA-36094 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

PS, we request you to please share your input PDF and TTF, so that we can also test the scenario with your resource files.


Thanks for addressing this, if you can give us a rough ETA for when this will be fixed that would be great.

I have attached the fonts below, we are basically adding a cover page to an existing PDF document, I am unable to send you a sample doc as it is generated with sensitive information but if you can work with these fonts on a document of your own and advise on a solution that would be great.



Hi Dave,

Thanks for your patience.

As we recently have noticed earlier reported issue, so its pending for review and is not yet resolved. However the font file has been associated with earlier reported issue and we will surely consider it during the resolution of this problem. As soon as we have some definite updates regarding its resolution, we will let you know. Please be patient and spare us little time. We are sorry for this delay and inconvenience.

The issues you have found earlier (filed as PDFJAVA-36094) have been fixed in Aspose.Pdf for Java 16.11.0.

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.