Cannot Get Image

I just convert word as a jpeg[Word Contains 12 Pages]… I want to get 12 pages one by one as a single image…But i cannot convert jpeg… and Image quality…

Hi there,

Thanks for your inquiry. Please use following code example to convert all pages of document to Jpeg. Hope this helps you.

Document doc = new Document(MyDir + @"in.docx");
ImageSaveOptions opts = new ImageSaveOptions(SaveFormat.Jpeg);
opts.PageIndex = 0;
opts.PageCount = doc.PageCount;
opts.Resolution = 300;
opts.PageSavingCallback = new HandlePageSavingCallback();
doc.Save(MyDir + @"17.2.0.Jpeg", opts);
private class HandlePageSavingCallback : IPageSavingCallback
{
    public void PageSaving(PageSavingArgs args)
    {
        args.PageFileName = string.Format(MyDir + @"Page_{0}.jpeg", args.PageIndex);
    }
}

Hi,

Hai How to Download Multipages as a single image(Not image series)…?

I use the following code to download the document as a jpeg

doc.Save(HttpContext.Current.Response, documentName + ".jpg", ContentDisposition.Attachment, options);

Here i don’t mention any file path to save my document…

Pls Help multiple pages with single image…

Thank you

Narendran

I use the following code to download the document as a jpeg

doc.Save(HttpContext.Current.Response, documentName + ".jpg", ContentDisposition.Attachment, options);

Here i don’t mention any file path to save my document…

then how can i get multiple pages in single jpeg…?

Hi Narendran,

Thanks for your inquiry. Aspose.Words does not offer any APIs to send multiple documents to client browser. In this case, you need to zip the output documents and send them to client browser. Please check following web links.

How to: Compress and Extract Files

Downloading multiple files in ASP.NET

If you want to render document’s pages to one single image, please use following code example. Hope this helps you.

// The user opens or builds a document.
Document doc = new Document(MyDir + "input.docx");
// This defines the number of columns to display the thumbnails in.
const int thumbColumns = 2;
// Calculate the required number of rows for thumbnails.
// We can now get the number of pages in the document.
int remainder;
int thumbRows = Math.DivRem(doc.PageCount, thumbColumns, out remainder);
if (remainder > 0)
    thumbRows++;
// Lets say I want thumbnails to be of this zoom.
const float scale = 0.25f;
// For simplicity lets pretend all pages in the document are of the same size, 
// so we can use the size of the first page to calculate the size of the thumbnail.
Size thumbSize = doc.GetPageInfo(0).GetSizeInPixels(scale, 96);
// Calculate the size of the image that will contain all the thumbnails.
int imgWidth = thumbSize.Width * thumbColumns;
int imgHeight = thumbSize.Height * thumbRows;
using (Bitmap img = new Bitmap(imgWidth, imgHeight))
{
    // The user has to provides a Graphics object to draw on.
    // The Graphics object can be created from a bitmap, from a metafile, printer or window.
    using (Graphics gr = Graphics.FromImage(img))
    {
        gr.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
        // Fill the "paper" with white, otherwise it will be transparent.
        gr.FillRectangle(new SolidBrush(Color.White), 0, 0, imgWidth, imgHeight);
        for (int pageIndex = 0; pageIndex < doc.PageCount; pageIndex++)
        {
            int columnIdx;
            int rowIdx = Math.DivRem(pageIndex, thumbColumns, out columnIdx);
            // Specify where we want the thumbnail to appear.
            float thumbLeft = columnIdx * thumbSize.Width;
            float thumbTop = rowIdx * thumbSize.Height;
            SizeF size = doc.RenderToScale(pageIndex, gr, thumbLeft, thumbTop, scale);
            // Draw the page rectangle.
            gr.DrawRectangle(Pens.Black, thumbLeft, thumbTop, size.Width, size.Height);
        }
        img.Save(MyDir + "Rendering.Thumbnails Out.png");
    }
}