Define Page Size when Rendering

How can I specify the size of the rendered Bitmap when using DocumentRenderer? I would expect to be able to specify the resolution or bitmap size that’s rendered.


Thanks for your inquiry. Unfortunately there is no built-in functionality for specifying image resolution during rendering. You can use custom function to achieve this. For example see the following code:

public void Test013()
    Document doc = new Document(@"Test013\in.doc");
    DocumentRenderer renderer = new DocumentRenderer(doc);
    Bitmap[] pages = renderer.GetPages();
    for (int i = 0; i < pages.Length; i++)
        Image picture = ResizeImage((Image)pages[i], 100, 100);
        picture.Save(String.Format(@"Test013\out_{0}.jpg", i));
/// Resize source image to specifed sze
/// Source image
/// Target width
/// Target height
/// Resized image
public static Image ResizeImage(Image sourceImage, int targetWidth, int targetHeight)
    float ratioWidth = (float)sourceImage.Width / targetWidth;
    float ratioHeight = (float)sourceImage.Height / targetHeight;
    if (ratioWidth > ratioHeight)
        targetHeight = (int)(targetHeight * (ratioHeight / ratioWidth));
        if (ratioWidth < ratioHeight)
            targetWidth = (int)(targetWidth * (ratioWidth / ratioHeight));
    // create target image
    Bitmap targetImage = new Bitmap(targetWidth, targetHeight, PixelFormat.Format24bppRgb);
    // set transform parameters 
    using (Graphics g = Graphics.FromImage(targetImage))
        g.CompositingQuality = CompositingQuality.HighQuality;
        g.SmoothingMode = SmoothingMode.HighQuality;
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        // resize image
        Rectangle rc = new Rectangle(0, 0, targetImage.Width, targetImage.Height);
        g.DrawImage(sourceImage, rc);
    return (Image)targetImage;

Hope this helps.
Best regards.

This approach works is acceptable when resizing the image smaller, but not when enlarging for purposes such as zooming.

Is there a way to determine the number of pages in a word document without calling renderer.GetPages()? I would think there would be a much more efficient way for getting the number of pages without actually rendering.


Thanks for your inquiry. Aspose.Words document represents content and formatting of a document, not its layout into lines and pages. This feature is called pagination and it is not released yet. Please see FAQ for more information.
You can try using BuildInDocumentProperties.Pages to get count of pages.
But this count could be not actual.
Best regards.

Thanks - that’s helpful. Do you have an estimate of when the word viewing will be out of beta?

Thanks for your inquiry. Unfortunately I can’t provide you any reliable estimate at the moment. The estimate was pushed several times.
Best regards.

I understand. The problem of rendering Word documents is massive and I like what I see - at least for a beta. Please have your sales team respond to the email I sent yesterday to sales.

Shelia Holt will be answering your email shortly. I have sent it to her a little bit ago. I will be out of the office for the next few days so please feel free to email her with any questions.