To address the issues you’re experiencing with font preservation and image conversion when converting a DOCX file to PDF using Aspose.Words, you can utilize specific options in the PdfSaveOptions class.
1. Font Preservation
To ensure that the fonts are preserved during the conversion, you can set the EmbedFullFonts property to true. This will embed all fonts found in the document into the PDF, which helps maintain the original appearance of the text.
Here’s a code snippet demonstrating how to do this:
using Aspose.Words;
using Aspose.Words.Saving;
Document doc = new Document("input.docx");
PdfSaveOptions saveOptions = new PdfSaveOptions
{
EmbedFullFonts = true // Embed all fonts
};
doc.Save("output.pdf", saveOptions);
2. Image Preservation
If images from the DOCX file are not appearing in the PDF, ensure that the images are correctly embedded in the document. You can also check the MetafileRenderingOptions to handle metafiles properly, which can sometimes affect image rendering.
Here’s how you can set up the MetafileRenderingOptions:
MetafileRenderingOptions metafileRenderingOptions = new MetafileRenderingOptions
{
EmulateRasterOperations = false, // Set to true if you want to emulate raster operations
RenderingMode = MetafileRenderingMode.VectorWithFallback // Use vector graphics with fallback to bitmap if necessary
};
PdfSaveOptions saveOptions = new PdfSaveOptions
{
MetafileRenderingOptions = metafileRenderingOptions
};
doc.Save("output.pdf", saveOptions);
Summary
By embedding fonts and configuring the metafile rendering options, you should be able to resolve the issues with font and image preservation during the DOCX to PDF conversion. Make sure to test these settings with your specific documents to ensure they meet your requirements.
If you continue to experience issues, consider checking the Aspose documentation or community forums for additional troubleshooting tips.
The problem might occur because fonts required to render the document are not availabe. The fonts are required to build document layout. If Aspose.Words cannot find the font used in the document, the font is substituted . This might lead into fonts mismatch and document layout differences due to the different fonts metrics. You can implement IWarningCallback to get notifications when font substitution is performed.
Please see our documentation to learn where Aspose.Words looks for fonts: https://docs.aspose.com/words/net/specifying-truetype-fonts-location/
If you add reference to SkiaSharp.NativeAssets.Linux, you should also install libfontconfig1 in your system. SkiaSharp.NativeAssets.Linux depends on this library. You can use the following command to install it:
If you do not have rights to install packages, or other reasons not to install libfontconfig1, you can simply use SkiaSharp.NativeAssets.Linux.NoDependencies , which does not require installation of libfontconfig1.
Currently it is recommended to use 2.88.x version of SkiaSharp. 3.x.x version of SkiaSharp has breaking API chnages that are not compatible with current version of Aspose.Words.