Large page rendering for Word Docs

Hi there

I’m using Aspose.Words to generate thumbnails of each page in a given Word document using a class library which uses Aspose.Words. Once generated, these images are then serialised and passed back up to a Win32 application via COM. Unfortunately, I’m finding that the memory consumption of our software increases dramatically after we generate these thumbnails, and is not released. I’m using the following code to generate the thumbnails:

ArrayList thumbnails = new ArrayList();

oDoc = new Document(path);

// Get thumbnails
for (int i = 0; i <oDoc.PageCount; i++)

    PageInfo pageInfo = oDoc.GetPageInfo(i);

    // Let's say we want the image at 50% zoom.
    const float MyScale = 1.00 f;

    // Let's say we want the image at this resolution.
    const float MyResolution = 96.0 f;

    Size pageSize = pageInfo.GetSizeInPixels(MyScale, MyResolution);

    Bitmap img = new Bitmap(pageSize.Width, pageSize.Height);

    Graphics gr = Graphics.FromImage(img);

    // You can apply various settings to the Graphics object.
    gr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

    // Fill the page background.
    gr.FillRectangle(Brushes.White, 0, 0, pageSize.Width, pageSize.Height);
    gr.DrawRectangle(Pens.Black, 0, 0, pageSize.Width, pageSize.Height);
    // Render the page using the zoom.
    oDoc.RenderToScale(i, gr, 0, 0, MyScale);



I’m wondering is there any way to reduce the file size by applying compression to the files in memory, or if there is any memory leak issues with the document rendering functionality in Aspose.Words?
If you could offer any advice I would appreciate it, thanks!



Thanks for your inquiry. Could you please attach your document here for testing? I will check the issue and provide you more information. Also, which version of Aspose.Words do you use?
Please try using the latest version 8.0.0.
Best regards,

Hi Andrey

I’ve attached a sample file. Just for your information, the memory consumption of our program was 40mb at launch, and after thumbnail generation it went up to 222mb even though the document only has 3 pages. We are using Aspose.Words 8.0.0 as well.




Thank you for additional information. I cannot reproduce the problem on my side. I tried using the following code:

Document doc = new Document(@"Test001\in.rtf");
for (int i = 0; i <doc.PageCount; i++)
    doc.SaveToImage(i, 1, string.Format(@"Test001\out_{0}.jpg", i), null);

And after converting the document to images, memory is immediately released. Maybe the problem on your side occurs because you do not dispose Bitmap objects and that is why memory is not released.
Best regards,

Hi Alexey

Thanks for your response. I do call dispose on the bitmap objects, see below

using(MemoryStream ms = new MemoryStream())
    // Serialise segments
    bf = new BinaryFormatter();

    bf.Serialize(ms, thumbnails);
    statedatasize = (int) ms.Length;
    statedata = new byte[statedatasize];
    ms.Seek(0, SeekOrigin.Begin);
    ms.Read(statedata, 0, statedatasize);

    byte[] data = (byte[]) newData;
    for (int i = 0; i <statedatasize; i++)
        newdata[i] = statedata[i]; //newdata is a "ref object" parameter

    for (int i = 0; i <thumbnails.Count; i++)
        ((Bitmap) thumbnails[i]).Dispose();

    thumbnails = null;
    statedata = null;





Hi Eric,

Thank you for additional information. As I mentioned in my previous post, I cannot reproduce the problem on my side. Could you please create a simple application, which will allow me to reproduce the problem on my side? I will check the issue one more time and provide you more information.
Best regards,