Font issue in linux container

Hello,

We are using licensed ASPOSE in our application. We are facing some issues regarding fonts in .doc and .pdf.

We have Calibri(Body) font in our templates but font is not matching after converting to PDF.

Is there any way to fix this issue?

To address the font issue you’re experiencing with Calibri(Body) in your .doc and .pdf files when using Aspose, you can embed the font directly into the PDF during the conversion process. This ensures that the font is included in the PDF file, which helps maintain the intended appearance across different platforms, including Linux containers.

Here are the steps you can follow to embed fonts in your PDF:

  1. Load the PDF Document: Use the Aspose.PDF library to load your existing PDF file.

  2. Embed the Font: You can embed the Calibri font by accessing the font properties and setting the embedding options. This can be done by iterating through the document’s pages and checking for the fonts used.

  3. Save the Document: After embedding the font, save the PDF document to ensure the changes are applied.

Here is a sample code snippet demonstrating how to embed a font in a PDF file using Aspose.PDF for .NET:

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

// Load the existing PDF document
Document pdfDocument = new Document("input.pdf");

// Iterate through all the pages
foreach (Page page in pdfDocument.Pages)
{
    // Check for text fragments and embed the font
    foreach (TextFragment textFragment in page.Paragraphs.OfType<TextFragment>())
    {
        // Set the font to Calibri and embed it
        textFragment.TextState.Font = FontRepository.FindFont("Calibri", true);
    }
}

// Save the updated PDF document
pdfDocument.Save("output.pdf");

Important Notes:

  • Ensure that the Calibri font is installed on the machine where the PDF is being generated. If it is not installed, you may need to include the font file in your project and load it programmatically.
  • Embedding fonts can increase the file size, but it guarantees that the document will render correctly on any device, regardless of the fonts installed on that device.

By following these steps, you should be able to resolve the font mismatch issue in your PDF documents. If you continue to experience problems, consider checking the font availability on your Linux container or reviewing the Aspose documentation for additional options related to font management.

For more detailed information on embedding fonts, you can refer to the Aspose documentation on Embedding Fonts in PDF.

Sources:
[1]: Embed Font In PDF File | Aspose.PDF for .NET API Reference