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

Free Support Forum - aspose.com

Get thumbnail images from pages

Hi,


is it possible with Aspose.Words to get a thumbnail image (JPEG) from each page of a Word document?

Best Regards
Andreas

Hi Andreas,


Please use the following code to generate thumbnail image of each page in Word document:

Document doc = new Document(MyDir + @“input.docx”);

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Jpeg);

options.PageCount = 1;

int pageCountDoc = doc.PageCount;

for (int pageCount = 0; pageCount < pageCountDoc; pageCount++)

{

options.PageIndex = pageCount;

MemoryStream imgStream = new MemoryStream();

doc.Save(imgStream, options);

Document temp = new Document();

DocumentBuilder builder = new DocumentBuilder(temp);

Shape img = builder.InsertImage(imgStream);

// Resize the image as per your needs

img.Width = 64;

img.Height = 64;

// Save the individual image to disk using ShapeRenderer class

ShapeRenderer renderer = img.GetShapeRenderer();

renderer.Save(MyDir + "out_" + pageCount + ".jpg", options);

}


Hope, this helps.

Best regards,

Hi,


thanks for this sample.

Can you please explain, which „usings“ I have to use for it ?

I think, for “Document I have to use “Aspose.Words.Document”.

But then, I don’t have a SaveFormat with “JPEG” for Aspose.words.ImageSaveOptions:

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Jpeg);

I only have

Aspose.Cells.SaveFormat or

Aspose.Pdf.SaveFormat or

Apose.Slides.Export.SaveFormat,

But they all don’t have “JPEG”

In the meantime, I found it:

Aspose.Words.Document doc = new Aspose.Words.Document(fileManager.GetFileAsStream(fileId));
Aspose.Words.Saving.ImageSaveOptions options4 = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg);
options4.PageCount = 1;


Thanks
Willi
Hi,

I got a now a JPEG.
I set the width and height to 250.
But when I check the resulting JPEG, then there is another width and height.

Question: How can I get a thumbnail, which has my dimensions (250 pixel)

Thanks for help

willikuehnis:

Hi,


thanks for this sample.

Can you please explain, which „usings“ I have to use for it ?

I think, for “Document I have to use “Aspose.Words.Document”.

But then, I don’t have a SaveFormat with “JPEG” for Aspose.words.ImageSaveOptions:

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Jpeg);

I only have

Aspose.Cells.SaveFormat or

Aspose.Pdf.SaveFormat or

Apose.Slides.Export.SaveFormat,

But they all don’t have “JPEG”


For this piece of code, you need to add following at the top:

using Aspose.Words;

using Aspose.Words.Saving;

using Aspose.Words.Drawing;

using Aspose.Words.Rendering;


Best regards,
willikuehnis:
Hi,

I got a now a JPEG.
I set the width and height to 250.
But when I check the resulting JPEG, then there is another width and height.

Question: How can I get a thumbnail, which has my dimensions (250 pixel)

Thanks for help


Please try using the following code:

Document doc = new Document(MyDir + @"input.docx");

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Jpeg);

options.PageCount = 1;

int pageCountDoc = doc.PageCount;

for (int pageCount = 0; pageCount < pageCountDoc; pageCount++)

{

options.PageIndex = pageCount;

MemoryStream imgStream = new MemoryStream();

doc.Save(imgStream, options);

Document temp = new Document();

DocumentBuilder builder = new DocumentBuilder(temp);

Shape img = builder.InsertImage(imgStream);

// Resize the image as per your needs

img.Width = ConvertUtil.PixelToPoint(250);

img.Height = ConvertUtil.PixelToPoint(250);

// Save the individual image to disk using ShapeRenderer class

ShapeRenderer renderer = img.GetShapeRenderer();

renderer.Save(MyDir + "out_" + pageCount + ".jpg", options);


Best regards,
Great,

this works.
(There was no description about the Unit (Pixel or Points)

But:
When I also set a new Resolution in the options, then I have to set the img.Width this way:
img.Width = ConvertUtil.PixelToPoint( mySizeInPixel* oldResolution / newResolution );


It's OK
Thanks





But it

Hi,


It is great you were able to find what you were looking for. Please let us know any time you have any further queries.

Best regards,