Embedding fonts license limitation problem

Hi there

I’m trying to embed fonts into a PDF. One font is TTF and the other is OTF. Neither of them seem to be embedding. I am using IsEmbedded = true; on each font.

Is this a limitation with the temporary license?

Regards,
Brett

@brettfisher,
If the temporary license is not expired yet, then you can test every aspect of the Aspose.Pdf for .NET API. Kindly send us your source PDF and code, so that we could investigate this scenario in our environment. We will let you know about the findings. Your response is awaited.

Best Regards,
Imran Rafique

Hi there

I set Font.FontOptions.NotifyAboutFontEmbeddingError = true; and then an exception was raised, stating:

Aspose.Pdf.FontEmbeddingException: Font embedding is prohibited because of license restrictions

I had thought that this was the Aspose license, but now I realise it is actually meaning the font I am using.

Please close this. Thank you for your time at looking at this.

Regards,
Brett

@brettfisher,
Thank you for the details. It is nice to hear from you that the problem has been resolved. Please feel free to contact us if you need any further assistance.

Best Regards,
Imran Rafique

Hi there

I’m having trouble understanding the font license types. The TTF font I have has a font embeddability of “Preview/Print” but Aspose will not let me embed it. It seems I can only embed if the font embedability is “Editable”.

As I understand it, the “Preview/Print” ought to allow us to embed the font.

Can you please comment on this?

Regards,
Brett

@brettfisher

Thanks for writing back.

Would you please share the font file, with which you are experiencing issue. We will test the scenario in our environment and address it accordingly.

Please find attached the respective font file.

FlamaSemicondensed-Light.zip (33.7 KB)

@brettfisher,
We managed to replicate the problem of not being able to embed font while creating a new PDF. The output PDF EmbedFontWhileDocCreation_out.pdf (3.6 KB) shows an error when we opened in the Acrobat. It has been logged under the ticket ID PDFNET-43109 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

We could not replicate the same error as you narrated. Kindly send us your complete code and source PDF (if any). We will investigate and share our findings with you. Your response is awaited.

Best Regards,
Imran Rafique

Hi there, here is a sample of my code:

    public static void Create(Stream stream, string fontPath)
    {
        SetLicense();

        var font = FontRepository.OpenFont(fontPath);
        font.IsEmbedded = true;
        font.FontOptions.NotifyAboutFontEmbeddingError = true;

        var document = new Document();
        var page = document.Pages.Add();

        var fragment = new TextFragment("Hello, world!");
        fragment.TextState.Font = font;
        fragment.TextState.FontSize = 20;

        page.Paragraphs.Add(fragment);

        document.Save(stream);
    }

The exception occurs due to font.FontOptions.NotifyAboutFontEmbeddingError being set to true. I suppose I did not accurately explain the issue (my apologies).

Furthermore, if I do not enable the above option, then on a Mac if the font is NOT installed on the system garbage appears in the PDF. I do not have access to a Mac right now, but I will upload a screenshot when I get the chance.

@brettfisher,
We have logged this information under the same ticket ID PDFNET-43109. We will let you know once a significant progress has been made in this regard.

Best Regards,
Imran Rafique

@brettfisher

Thanks for your patience.

We are pleased to inform you that earlier reported issue PDFNET-43109, has been resolved in latest version Aspose.Pdf for .NET 17.12. Please note that the input font has a license type “Preview & Print embedding” and this license has such requirements (i.e “Documents containing Preview & Print fonts must be opened “read-only;” no edits can be applied to the document”). You were trying to embed font into editable document, which is prohibited by requirements of font’s license.

In order to embed this font into new document it’s necessary to make document non-editable. It can be accomplished via conversion into PDF/A format. All PDF/A documents have such requirement that all fonts must be embedded into document, so no need of using font.IsEmbedded = true command.

Also using of empty TextFragment object in your code, is not fully correct for this case - empty TextFragment leads to an additional Arial font which has no text and this additional font without text, violates PDF/A requirements. So in order to make document PDF/A compliant better to use approach with non-empty TextFragment and set desired font for this TextFragment directly.

Following code snippet creates document with your text and converts this document into PDF/A-1B format:

FolderFontSource fs = new FolderFontSource(@"C:\Pdf\test166\");
FontRepository.Sources.Add(fs);

// Instantiate Pdf object by calling its empty constructor
Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

// Create a section in the Pdf object
Aspose.Pdf.Page page = doc.Pages.Add();

Aspose.Pdf.Text.TextFragment fragment = new TextFragment(" This is a sample text using Custom font.");
fragment.TextState.Font = FontRepository.FindFont("FlamaSemicondensed-Light");

page.Paragraphs.Add(fragment);

//Convert document into PDF/A format
doc.Convert(new MemoryStream(), PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
// Save PDF Document
doc.Save(@"C:\Pdf\test166\EmbedFontWhileDocCreation_out2.pdf");

EmbedFontWhileDocCreation_out2.pdf (39.7 KB)

Resultant document for above code snippet is attached - “EmbedFontWhileDocCreation_out2.pdf”. It has font “FlamaSemicondensed-Light” as embedded.

Please try using the latest release version and in case you face any issue, please feel free to contact us.