Export Word document to IMage at 300dpi

Is it possible to export a word document to an image file (png) and set the DPI to 300. 

Thanks, Martin


1 Reply

HC Hemalatha Chiranjeevulu Syncfusion Team August 9, 2021 06:53 AM UTC

Hi Martin,

Thank you for contacting Syncfusion support.

From the details, we have found that your requirement is to convert the Word document to Image and set the desired DPI value to an image. Please refer the below code example to achieve your requirement.

 
//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;
//Declare variables to hold custom width and height
int customWidth = 1500;
int customHeight = 1000;
foreach (Image image in images)
{
MemoryStream stream =
new MemoryStream();
image.Save(stream, ImageFormat.Png);
//Creates a bitmap of specific width and height
Bitmap bitmap = new Bitmap(customWidth, customHeight, PixelFormat.Format32bppPArgb);
//Gets the graphics from image
Graphics graphics = Graphics.FromImage(bitmap);
//Sets the resolution
bitmap.SetResolution(300, 300);
//Recreates the image in custom size
graphics.DrawImage(System.Drawing.Image.FromStream(stream), new Rectangle(0, 0, bitmap.Width, bitmap.Height));
//Saves the image as bitmap
bitmap.Save("ImageOutput" + Guid.NewGuid().ToString() + ".png");
i++;
}
//Closes the document
wordDocument.Close(); 

Please refer the below UG documentation to know how to convert Word document to image:
https://help.syncfusion.com/file-formats/docio/word-to-image

Please let us know if you have any other questions.

Regards,
Hemalatha C


Loader.
Up arrow icon