Articles in this section
Category / Section

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

2 mins read

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()

 

Note

A new version of Essential® Studio® for ASP.NET is available. Versions prior to the release of Essential® Studio® 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential® Studio® for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.

The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential® Studio® for ASP.NET. Although Syncfusion® will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.

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 forumsDirect-Trac, 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