3

I have an .net core 2 application. I use syncfusion, the docIO libraries for working with word documents. I have a word document and i want to change format of all images inside the document to .png

I have found the WPicture objects iterating over the paragraphs:

 if (paragraphItem is WPicture)
 {
   var wpicture = paragraphItem as WPicture;
   var imageBytes = wpicture.ImageBytes;

 }

How can i change the format of WPicture object?

Birtija
  • 87
  • 3
  • 10

1 Answers1

1

Essential DocIO doesn’t have a direct API to change image format. Since System.Drawing namespace is not available in ASP.NET Core platform you need to use any one of the alternative image processing library (as mentioned in MSDN) to change the image format of the picture.

Here, the below example code used the CoreCompat helper library to change the image format:

   WPicture picture = item as WPicture;
  //Load the DocIO WPicture image bytes into CoreCompat Image instance.
  Image image = Image.FromStream(new MemoryStream(picture.ImageBytes));
  //Check image format, if format is other than png then convert the image as png format.
  if (!image.RawFormat.Equals(ImageFormat.Png))
  {
      MemoryStream imageStream = new MemoryStream();
      image.Save(imageStream, ImageFormat.Png);
      //Load the png format image into DocIO WPicture instance.
      picture.LoadImage(imageStream);
      imageStream.Dispose();
   }
   //Resize the picture width and height.
   picture.Width = 400;
   picture.Height = 400;
Vijay
  • 78
  • 1
  • 10
  • Thanks for answering, and for the resizing the picture, is the some to set set the max size of the picture and not just append dirrect values? – Birtija Nov 23 '17 at 12:19
  • Please let me know whether your requirement is to resize the image to page size or its original size (100% scaling). – Vijay Nov 27 '17 at 09:30
  • i need to resize the image to the page size. – Birtija Nov 30 '17 at 09:16