Converting a document to PDF on a Linux machine generates this error:
com.aspose.pdf.exceptions.FontNotFoundException: Font OpenSansRegular can not found.
com.aspose.pdf.internal.l5h.l1n.l1h(Unknown Source)
com.aspose.pdf.internal.l9f.l0v.lI(Unknown Source)
com.aspose.pdf.internal.l9k.l0f.lI(Unknown Source)
com.aspose.pdf.internal.l9k.l0f.lI(Unknown Source)
com.aspose.pdf.internal.l9k.l0f.lI(Unknown Source)
com.aspose.pdf.internal.l9k.l0f.lI(Unknown Source)
com.aspose.pdf.internal.l9k.l0f.l6if(Unknown Source)
com.aspose.pdf.internal.l9k.l0f.l3n(Unknown Source)
com.aspose.pdf.internal.l9k.l1l.l5v(Unknown Source)
com.aspose.pdf.internal.l9k.l0f.lI(Unknown Source)
com.aspose.pdf.ADocument.lI(Unknown Source)
com.aspose.pdf.Document.lI(Unknown Source)
com.aspose.pdf.ADocument.convertInternal(Unknown Source)
com.aspose.pdf.Document.convertInternal(Unknown Source)
com.aspose.pdf.ADocument.convert(Unknown Source)
com.aspose.pdf.Document.convert(Unknown Source)
Here is the code to reproduce it:
OutputStream logFos = new FileOutputStream(log);
Document pdfDocument = new Document(inFile.getPath());
pdfDocument.convert(logFos, PdfFormat.PDF_A_2A, ConvertErrorAction.Delete);
@fabio.parise
Summary
Aspose.PDF for Java cannot locate the OpenSansRegular font on your Linux machine, so the PDF/A‑2A conversion aborts with a FontNotFoundException.
Why it happens
- PDF/A conversion requires every font used in the document to be embedded. If a font cannot be resolved, Aspose.PDF throws
FontNotFoundException.
- On Linux the library searches for fonts via the system font‑config cache or through a font repository that must be populated before the
Document object is created.
- The font is either not installed on the OS, or it is added to the repository after the document has already been parsed, which is too late for the conversion step.
What to do next
- Install the font on the Linux system (recommended)
sudo mkdir -p /usr/share/fonts/truetype/custom
sudo cp OpenSansRegular.ttf /usr/share/fonts/truetype/custom/
sudo fc-cache -f -v # rebuild font‑config cache
# Verify the installation
fc-list | grep -i opensans
After the font appears in the fc-list output, run your conversion again.
- Register the font programmatically before creating the
Document
import com.aspose.pdf.FontRepository;
import com.aspose.pdf.MemoryFontSource;
import com.aspose.pdf.FontSettings;
import com.aspose.pdf.Document;
import com.aspose.pdf.SaveOptions;
import com.aspose.pdf.PdfSaveOptions;
import com.aspose.pdf.PdfCompliance;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
// 1) Add the font to the global repository
FontRepository repo = FontRepository.getInstance();
repo.addFont("path/to/OpenSansRegular.ttf"); // absolute path
// or, if you have the font bytes:
// byte[] fontBytes = Files.readAllBytes(Paths.get("path/to/OpenSansRegular.ttf"));
// repo.addFont(new MemoryFontSource(fontBytes));
// 2) (optional) configure a FontSettings object
FontSettings fontSettings = new FontSettings();
fontSettings.setFontsFolder("path/to/font/folder", true); // true = recursive
// 3) Create the document *after* the font is registered
Document pdfDocument = new Document(inFile.getPath()); // or new Document(htmlString, new HtmlLoadOptions())
pdfDocument.setFontSettings(fontSettings); // if you used FontSettings
// 4) Save as PDF/A‑2A
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setCompliance(PdfCompliance.PDF_A_2A);
try (OutputStream out = new FileOutputStream("output.pdf")) {
pdfDocument.save(out, saveOptions);
}
- Verify the Aspose.PDF for Java version
System.out.println("Aspose.PDF version: " + Document.getVersion());
If you are using an older release, consider upgrading to the latest version available on Maven Central, as newer builds contain improvements to font‑fallback handling for PDF/A.
- Ensure the correct load options for the source type
When converting from an HTML string use HtmlLoadOptions:
import com.aspose.pdf.HtmlLoadOptions;
Document pdfDocument = new Document(htmlString, new HtmlLoadOptions());
// Apply the same font‑registration steps before this line.
- Collect additional diagnostics if the issue persists
- Provide the Linux distribution and version (e.g., Ubuntu 22.04, Alpine).
- Confirm the absolute path to the
OpenSansRegular.ttf file.
- Indicate whether you already use custom
FontSettings or FontRepository code.
- State the exact Aspose.PDF for Java version in use.
Gathering this information will help narrow down any remaining configuration problems. Once the font is visible to Aspose.PDF—either through the operating system or via the repository before the Document is instantiated—the PDF/A‑2A conversion should complete without a FontNotFoundException.
I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.
I noticed that release notes of Aspose.PDF for Java 25.9 contains a bug fix about a similar problem:
PDFJAVA-44889: Pdf to PDF_A_1B: “FontNotFoundException: Font OpenSansRegular can not found.” Linux OS
Can you share details about this fix and if there is a workaround we can apply to our production systems that are using version 25.5 of the library?
@fabio.parise
The bug was related to the missing fonts in the system. The scenario was reproduced in Linux (Red Hat) environment and was resolved by updating the configuration of the project. The configuration must include installation of the fonts in the system. Nevertheless, have you tried installing missing fonts? If issue is still happening, would you kindly share your sample PDF with us with your environment details? We will test the scenario in our environment and address it accordingly.