we have an application where we convert every page of a pdf-document into an image. We face the Situation, that the rendered picture shows completely wrong characters compared to all viewers.
We did a little research and think that the problem is the containing cmap with the ToUnicode method within the pdf, which is propably completely ignored by the viewers.
Is there a possibility to render the images just like a viewer would do it ?
Our code looks just like this:
var jpegDevice = new Aspose.Pdf.Devices.JpegDevice(new Resolution(96),150);
using (var document = new Aspose.Pdf.Document(dokumentPath))
{
for (int pageCount = 1; pageCount <= document.Pages.Count; pageCount++)
{
Summary
The most common reason why rasterising a PDF page to an image (e.g., JPEG) produces garbled or wrong characters is that the renderer cannot locate the exact fonts or the required CMap/ToUnicode information that the PDF relies on. When the font is missing or the CMap is ignored, Aspose.Pdf falls back to a substitute font and the glyph‑to‑character mapping is lost, resulting in the visual mismatch you see.
Why it happens
Fonts are not embedded – If the PDF does not embed the fonts it uses, Aspose.Pdf must find matching fonts on the host machine. If it cannot, it substitutes a different font, which often has a completely different glyph order.
CMap/ToUnicode streams are external or ignored – Some PDFs store the character‑code‑to‑Unicode mapping in an external CMap. If the renderer does not load that CMap (or the associated font is missing), the mapping is discarded and characters appear as unrelated symbols.
Default font‑substitution settings – The SDK’s default substitution logic may pick a font that does not contain the required glyphs, especially for non‑Latin scripts.
What to do next
Verify the PDF actually embeds its fonts
Open the file in Adobe Acrobat (File → Properties → Fonts). If the fonts are listed as Embedded or Embedded Subset, the problem is not missing fonts. If they are Not Embedded, you need to supply the missing font files.
Make the required fonts available to Aspose.Pdf
// Folder that contains the missing .ttf/.otf files
string fontFolder = @"C:\MyFonts";
// Register the folder (recursive = true)
Aspose.Pdf.FontRepository.AddFontFolder(fontFolder, true);
Load the PDF with options that keep font substitution under control and enable external CMap loading
var loadOptions = new Aspose.Pdf.LoadOptions
{
// Prevent automatic substitution with unrelated fonts
FontSubstitution = false,
// Ensure external CMap streams are processed if present
ResourceLoadingOptions = new Aspose.Pdf.ResourceLoadingOptions
{
LoadExternalCMaps = true
}
};
var document = new Aspose.Pdf.Document(dokumentPath, loadOptions);
Render the pages to JPEG (or another raster format) after the above configuration
var jpegDevice = new Aspose.Pdf.Devices.JpegDevice(new Aspose.Pdf.Devices.Resolution(96), 150);
for (int i = 1; i <= document.Pages.Count; i++)
{
string outPath = Path.Combine(resultDirectory, $"Page_{i}.jpeg");
jpegDevice.Process(document.Pages[i], outPath);
}
Test with a different image format (PNG, BMP) to rule out JPEG‑specific artefacts.
Upgrade Aspose.Pdf if you are on an older version – newer releases contain fixes for font‑substitution and CMap handling. You can print the version at runtime:
If the problem persists, collect diagnostic information and open a support ticket with Aspose:
A minimal PDF that reproduces the issue.
The exact Aspose.Pdf version you are using.
Any global settings that might affect font handling (e.g., custom FontSubstitution logic).
Note: The evidence retrieved for this request does not contain specific documentation about Aspose.Pdf’s handling of CMaps or font substitution, so the guidance above is based on typical behaviour of the Aspose.Pdf rendering engine and common troubleshooting steps. If you need confirmation for a particular SDK version, please refer to the official Aspose.Pdf documentation or contact Aspose support directly.
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.
The Used Assembly.Version is 25.11.0.0. We already tested with 25.10. and 25.2 and none of them were able to create the right image.
Also the suggestion to instantiate LoadOptions is not possible, its an abstract class.
Also the Fonts are all embedded, always.
I hope these information helps. The problem is that we cant recreate this behavior and we only have documents from our customers, which we cant publish.