Rendering / Converting Word document to Image
22 Aug 2019 / 3 minutes to read
The Essential DocIO converts the Word document to images using the RenderAsImages
method. The following assemblies are referred for converting Word to image:
Assembly Name | Description |
---|---|
Syncfusion.DocIO.Base |
This assembly has the core features for creating and manipulating Word documents. |
Syncfusion.Compression.Base |
This assembly is used to package the Word documents. |
Syncfusion.OfficeChart.Base |
This assembly has features to work with chart in Word document. |
The following assemblies are referred additionally for converting charts during Word to image conversion:
Assembly Name | Description |
---|---|
Syncfusion.OfficeChartToImageConverter.WPF |
This assembly is used to convert the chart to image. |
Syncfusion.SfChart.WPF |
This is supporting assembly for Syncfusion.OfficeChartToImageConverter.WPF |
The following namespaces are required to compile the code in this topic:
- using Syncfusion.DocIO
- using Syncfusion.DocIO.DLS
- using Syncfusion.OfficeChart
- using Syncfusion.OfficeChartToImageConverter
TIPS
- You can get the good quality converted images by specifying the image type as Metafile.
- You can specify the quality of the converted charts by setting the scaling mode.
The following code illustrates how to convert the Word document to image.
//Loads an existing Word document
WordDocument wordDocument = new WordDocument("Template.docx", FormatType.Docx);
//Initializes the ChartToImageConverter for converting charts during Word to image conversion
wordDocument.ChartToImageConverter = new ChartToImageConverter();
//Sets the scaling mode for charts (Normal mode reduces the file size)
wordDocument.ChartToImageConverter.ScalingMode = ScalingMode.Normal;
//Converts word document to image
Image[] images = wordDocument.RenderAsImages(ImageType.Bitmap);
int i = 0;
foreach (Image image in images)
{
//Saves the images as jpeg
image.Save("WordToImage_" + i + ".jpeg", ImageFormat.Jpeg);
i++;
}
//Closes the document
wordDocument.Close();
'Loads an existing Word document
Dim wordDocument As New WordDocument("Template.docx", FormatType.Docx)
'Initializes the ChartToImageConverter for converting charts during Word to image conversion
wordDocument.ChartToImageConverter = New ChartToImageConverter()
'Sets the scaling mode for charts (Normal mode reduces the file size)
wordDocument.ChartToImageConverter.ScalingMode = ScalingMode.Normal
'Converts word document to image
Dim images As Image() = wordDocument.RenderAsImages(ImageType.Bitmap)
Dim i As Integer = 0
For Each image As Image In images
'Saves the images as jpeg
image.Save("WordToImage_" & i & ".jpeg", ImageFormat.Jpeg)
i += 1
Next
'Closes the document
wordDocument.Close()
//DocIO supports Word to image conversion in Windows Forms, WPF, ASP.NET and ASP.NET MVC platform alone
//DocIO supports Word to image conversion in Windows Forms, WPF, ASP.NET and ASP.NET MVC platform alone
//DocIO supports Word to image conversion in Windows Forms, WPF, ASP.NET and ASP.NET MVC platform alone
NOTE
- Word to Image conversion is not supported in Silverlight, Windows Phone, WinRT, Universal, Xamarin, ASP.NET Core, Blazor and Universal Windows Platform applications.
- In Azure Web Service and Azure APP Service, .NET GDI+ (System.Drawing) does not support the Metafile image (vector image). So, the image will be generated as Bitmap (raster image).
- Creating an instance of the ChartToImageConverter class is mandatory to convert the charts present in the Word document to Image. Otherwise, the charts are not preserved in the generated image.
- The ChartToImageConverter is supported from .NET Framework 4.0 onwards.
- Total number of images may vary based on unsupported elements in the input Word document.
- Word to Image conversion has the same limitations and unsupported elements of Word to PDF conversion.
Was this page helpful?
Yes
No
Thank you for your feedback!
Thank you for your feedback and comments. We will rectify this as soon as possible!
An unknown error has occurred. Please try again.
Help us improve this page