Click here to Skip to main content
14,828,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to compress inserted image in word using DSOFramer control.
Posted
Comments
Yousho 14-Apr-16 7:41am
   
I'm not sure how you can do that with the mentioned control, however here is how you can do this with VB.NET component for word documents:

DocumentModel doc = DocumentModel.Load("Sample.docx");

foreach (Picture pic in doc.GetChildElements(true, ElementType.Picture).Cast<Picture>().ToArray())
{
Layout picLayout = pic.Layout;
int width = (int)LengthUnitConverter.Convert(picLayout.Size.Width, LengthUnit.Point, LengthUnit.Pixel);
int height = (int)LengthUnitConverter.Convert(picLayout.Size.Height, LengthUnit.Point, LengthUnit.Pixel);

using (Image image = Image.FromStream(pic.PictureStream))
using (Bitmap bitmap = new Bitmap(image, width, height))
{
MemoryStream newPicStream = new MemoryStream();
bitmap.Save(newPicStream, image.RawFormat);
Picture newPic = new Picture(doc, newPicStream);
newPic.Layout = pic.Layout;
pic.Content.Start.InsertRange(newPic.Content);
pic.Content.Delete();
}
}

doc.Save("Sample.docx");

1 solution

For the general .NET compression, you can use System.IO.Compression namespace with few utilities like GZIPStream, DeflateStream, etc. Reference is at http://msdn.microsoft.com/en-us/library/system.io.compression.aspx[^]

DSOFramer control is a third party product. If you are asking about the compression specific to the control, then product provider can help you.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900