Articles in this section
Category / Section

How is custom resolution supported in Word document to image conversion in .NET MVC ?

2 mins read

No. Currently, DocIO doesn’t support converting a Word document into an image with custom resolution. However, this can be achieved by changing the resolution of an image before saving it. The following code snippets show 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 customResolution = 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 * customResolution) / defaultImageResolution), (int)((image.Height * customResolution) / defaultImageResolution), PixelFormat.Format32bppPArgb);
           // Set the custom resolution (500)
           bitmap.SetResolution(customResolution, customResolution);
           // 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 custom resolution is supported in Word document to image conversion in .NET MVC.

You can refer to our .NET MVC Word document feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our .NET MVC Word document 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 or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied