We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Save document's page to image using C#

the image saved using method

docSrc.SaveToImage(0, 1, @“C: ests.jpg”, null);

is same of the size as of page, any way to save is same as size of text, any possible way to ignore empty spaces?


Hi

Thanks for your query. Please use the latest version of Aspose.Words for .NET and use RenderToSize or RenderToScale methods of Document Class. Let us know, If you have any more queries.

private static void SaveToImage(Document doc, int pageIndex, string imageName, int width, int height)

{

using (Bitmap bmp = new Bitmap(width, height))

{

// User has some sort of a Graphics object. In this case created from a bitmap.

using (Graphics gr = Graphics.FromImage(bmp))

{

Color backgroundColor = doc.PageColor;

if (backgroundColor == Color.Empty)

backgroundColor = Color.White;

gr.FillRectangle(new System.Drawing.SolidBrush(backgroundColor), 0, 0, width, height);

gr.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

gr.PageUnit = GraphicsUnit.Pixel;

doc.RenderToSize(pageIndex, gr, 0f, 0f, width, height);

bmp.Save(imageName);

}

}

}

problem is still the same, how do i calculate the exact width & height of the text, not the complete page!

i just need the image to be sized same as text’s!

Hi,

Please accept my apology for late response. I regret to share with you that Aspose.Words does not support the requested feature. However, I will try to share a workaround soon.

Hi there,


Thanks for your inquiry.

Alternatively you can add the text you want to export to image to a shape and then save that directly to image on it’s own. Please see the following section of the documentation for details: http://www.aspose.com/docs/display/wordsnet/How+to++Render+Shapes+Separately+from+a+Document

Also if you want to render any node or cut off all “blank” space around the text then the work around class called RenderNode attached to this thread might be helpful: http://www.aspose.com/community/forums/313104/image-repeater/showthread.aspx#313104

Thanks,