I’m using Aspose.Words to convert a DOCX file to an image. However, I noticed that it re-renders embedded documents/objects. I want to keep the object’s original preview EMF so the output image matches what I see in Word. Is that possible?
To clarify: during DOCX-to-image conversion, I’d like embedded OLE objects to retain the same preview image (EMF) that Word displays. I’ve found that when the embedded object is an audio file or another document, Aspose.Words’ rendering makes the exported image look different from Word. Is there a way to achieve this?
Example docx:
物件跑版1.docx (23.4 KB)
@SzuChiChen
To retain the original EMF preview of embedded OLE objects during the conversion of a DOCX file to an image using Aspose.Words, you can utilize the ImageSaveOptions
class. This class allows you to specify how the document should be rendered, including the handling of OLE objects.
Cause
The issue of OLE object previews not being retained during conversion often arises from the default rendering settings in Aspose.Words.
Solution
To address this, you can set the OLEObjectsRenderingMode
property to Png
in the ImageSaveOptions
. This ensures that the original preview image of the OLE objects is preserved as they appear in Word.
Here’s a basic example of how to implement this:
Document doc = new Document("input.docx");
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png)
{
// Set the option to preserve OLE object previews
OLEObjectsRenderingMode = OLEObjectsRenderingMode.Png
};
// Save the document as an image
doc.Save("output.png", options);
Next Steps
If you find that the output still does not match what you see in Word, check the version of Aspose.Words you are using. Ensure you are on the latest version, as improvements and bug fixes are regularly made. Additionally, review the documentation for any other rendering options that may enhance the output quality.
If you have any further questions or need additional assistance, feel free to ask!
var saveOptions = new ImageSaveOptions(SaveFormat.Png)
{
OLEObjectsRenderingMode = OLEObjectsRenderingMode.Png // Cannot find this property
};
I saw references to OLEObjectsRenderingMode
, but I can’t find this property on ImageSaveOptions
. Which NuGet package am I missing?
Aspose.Words: 25.8.0
@SzuChiChen To get the output closer to MS Word it is required to enable open type features. Aspose.Words.Shaping.Harfbuzz package provides support for OpenType features in Aspose.Words using the HarfBuzz text shaping engine. You should enabling open type features to get the expected result. To achieve this you should add reference to Aspose.Words Shaping Harfbuzz
plugin and use the following code to convert your document:
Document doc = new Document(@"C:\Temp\in.docx");
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
doc.Save(@"C:\Temp\out_HarfBuzz.png");
out_HarfBuzz.png (3.1 KB)
@alexey.noskov Thanks for your suggestion.
However, the output result is still not as expected. For example, the “—” symbol should be displayed in vertical orientation, but in the Harfbuzz result it remains horizontal.
Does this mean that the font used does not support vertical glyph substitution for this character?
The reason I’m asking is that in MS Word the same text is rendered correctly in vertical orientation, so I’d like to understand why the result differs.
expeceted Result:

HarfBuff Result:
@SzuChiChen The problem looks strange. PDF rendered using MS Word looks the same as PDF rendered by Aspose.Words: ms.pdf (49.6 KB)
@alexey.noskov You’re right, the behavior does seem quite strange. When I use Aspose.Words to save the document as a new DOCX, the result looks identical to the original. However, when exporting to an image, the output still differs from what I see in Word.
As an alternative approach, I’m wondering if it would be possible to modify or replace the text inside the OLE object (e.g., Word.Picture.8
) so that the rendered output matches Word’s display.
Is such a workaround technically feasible with Aspose.Words, or would you recommend a different solution?
@SzuChiChen Unfortunately, there is no way to replace the text inside the OLE object. If you are using .NET Framework 4.6.1 or 4.6.2 version of Aspose.Words. You can get expected output using the following code:
Document doc = new Document(@"C:\Temp\in.docx");
PdfSaveOptions opt = new PdfSaveOptions();
opt.MetafileRenderingOptions.RenderingMode = MetafileRenderingMode.Bitmap;
doc.Save(@"C:\Temp\out.pdf", opt);
out.pdf (6.1 KB)
In such case GDI+ is used to render the EMF image and the result is the same as shown in MS Word. Unfortunately, this will not work in .NET Standard and .NET Core versions, since GDI+ is not used in these versions.
@alexey.noskov I’m using .NET Framework 4.8 and it resolves most of the issues. This has been a big help—thank you for your support!
1 Like