Boxes appear in generated PDF due to missing fonts — Need help embedding fonts in Aspose.PDF for .NET (Lambda environment)

I’m using Aspose.PDF for .NET to generate PDF files in an AWS Lambda environment.
The issue I’m facing is that boxes (□) appear instead of text in the generated PDFs — this seems to happen because the required fonts aren’t available in the Lambda runtime.

Since AWS Lambda has limited filesystem access and size constraints, I’d prefer not to include additional font files in a Lambda Layer.

Could you please advise on:

  1. How to embed fonts directly in the generated PDF using Aspose.PDF for .NET, so the output displays correctly even when the fonts aren’t installed on the system?
  2. Whether Aspose can embed standard fonts (e.g., Arial, Times New Roman, etc.) without explicitly providing font files?
  3. Any code examples or recommended settings for ensuring fonts are embedded properly?

code snippet:
private IDocumentContentModel ConvertTo(byte[] source, SaveFormat format)
{
using var inputStream = new MemoryStream(source);
Document doc = new Document(inputStream);
using MemoryStream outputStream = new MemoryStream();
doc.Save(outputStream, format);

 return new DocumentContentModel(outputStream.ToArray(), doc.PageCount);

}

@efatima

To address the issue of missing fonts in your generated PDFs using Aspose.PDF for .NET in an AWS Lambda environment, follow these steps:

  1. Using Standard Fonts: Aspose.PDF supports standard fonts like Arial and Times New Roman, which do not require additional font files. These fonts are typically available on most systems and are embedded automatically when used in your document.

  2. Code Example: Below is a code snippet that demonstrates how to set a standard font in your PDF:

using Aspose.Pdf;
using Aspose.Pdf.Text;

private IDocumentContentModel ConvertTo(byte[] source, SaveFormat format)
{
    using var inputStream = new MemoryStream(source);
    Document doc = new Document(inputStream);
    
    // Set the font for the text
    foreach (var page in doc.Pages)
    {
        TextFragment textFragment = new TextFragment("Your text here");
        textFragment.TextState.Font = FontRepository.FindFont("Arial"); // Use a standard font
        page.Paragraphs.Add(textFragment);
    }

    using MemoryStream outputStream = new MemoryStream();
    doc.Save(outputStream, format);

    return new DocumentContentModel(outputStream.ToArray(), doc.PageCount);
}

This code sets the font to Arial, which should be embedded in the PDF, preventing the appearance of boxes instead of text.

By following these steps, you should be able to generate PDFs that display correctly without the need for additional font files in your AWS Lambda environment.

If you have further questions or need additional assistance, feel free to ask!

Hello Aspose Support Team,

Thank you for your response.

To clarify, I do NOT want to change or substitute fonts during PDF generation. The generated PDF must contain exactly the same fonts as used in the original Word document, without any font replacement, fallback, or modification.

Please let me know how this can be achieved, or if there are any limitations I should be aware of.

Thanks.

@efatima

Korisnik traži pomoć oko ugradnje fontova iz izvornog Word dokumenta u PDF-u koristeći Aspose.PDF za .NET u AWS Lambda okruženju, bez zamjene fontova. Potrebna je tehnička podrška za postizanje točnog zadržavanja fontova.

Could you please guide me from where I get technical support?

@efatima

We need to investigate this scenario in details. For our reference, would you please provide sample source and output PDFs along with the sample code snippet? We will log an investigation ticket and share the ID with you.