How is custom resolution supported in Word document to image conversion in WinForms ?
No. Currently DocIO doesn’t have support to convert the Word document into image with custom resolution. However, we can achieve this by changing the resolution of an image before saving it. The following code snippets shows how to change the resolution of an image.
C#
//Loads an existing Word document WordDocument wordDocument = new WordDocument("Template.docx", FormatType.Docx); //Converts word document to image Image[] images = wordDocument.RenderAsImages(ImageType.Bitmap); int imageIndex = 0; int customReslution = 500; int defaultImageResolution = 96; foreach (Image image in images) { //Create a bitmap of specific width(500) and height(500) Bitmap bitmap = new Bitmap((int)((image.Width * customReslution) / defaultImageResolution), (int)((image.Height * customReslution) / defaultImageResolution), PixelFormat.Format32bppPArgb); //Set the custom resolution (500) bitmap.SetResolution(customReslution, customReslution); //Get graphics from the custom size bitmap image Graphics graphics = Graphics.FromImage(bitmap); //Recreate the image from stream using specified width and height graphics.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height)); //Save the bitmap bitmap.Save("WordToImage_" + imageIndex + ".png", ImageFormat.Png); imageIndex ++; } //Closes the document wordDocument.Close();
VB
'Loads an existing Word document Dim wordDocument As New WordDocument("Template.docx", FormatType.Docx) 'Converts word document to image Dim images As Drawing.Image() = wordDocument.RenderAsImages(ImageType.Bitmap) Dim imageIndex As Integer = 0 Dim customResolution As Integer = 500 Dim defaultImageResolution As Integer = 96 For Each image As Drawing.Image In images 'Create a bitmap of specific width(500) and height(500) Dim bitmap As New Bitmap(CInt((image.Width * customResolution) / defaultImageResolution), CInt((image.Height * customResolution) / defaultImageResolution), PixelFormat.Format32bppPArgb) 'Set the custom resolution (500) bitmap.SetResolution(customResolution, customResolution) 'Get graphics from the custom size bitmap image Dim graphics As Graphics = Graphics.FromImage(bitmap) 'Recreate the image from stream using specified width and height graphics.DrawImage(image, New Rectangle(0, 0, bitmap.Width, bitmap.Height)) 'Save the bitmap bitmap.Save("WordToImage_" + imageIndex.ToString() + ".png", ImageFormat.Png) imageIndex += 1 Next 'Closes the document wordDocument.Close()
Conclusion
I hope you enjoyed learning about how is custom resolution supported in Word document to image conversion in WinForms.
You can refer to our WinForms Word document feature tourpage to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Word example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!