I tried to convert the first page of a pdf document to a png file.
Works fine so far. I can set resolution and width, height.
As I wanted to create a thumbnail as preview image, I do only want to set the width parameter. In this case the height should be set automatically to not change the scale of the png.
How can I achieve this?
Kind regards, Yves
So something like this?:
Ok for explanation.
I want to create a preview of the first pdf page as PNG file to preview it fast in a web environment. In the past I used Image Magicks and Ghostscript for this task.
Now with Aspose PDF I can directly save a PDF document to a PNG file.
But the requirement is max width AND/OR max height.
So in my case I set for example 800x600 max width and height. So I needed to determine the scale of the page and set width to max 800 / 600 but width and height should not be higher then the max values. So whatever scale the PDF document has I can create a preview with the correct scale.
Hope this clarify my question and my solution after the correct in the first answer.
// Create Resolution object<o:p></o:p>
var res = new Resolution(resolution);
// now scale width and height
var page = pdfDocument.Pages[pageCount];
var height_scale = page.Rect.Height / page.Rect.Width;
var width_scale = page.Rect.Width / page.Rect.Height;
var newWidth = width;
var newHeight = newWidth * height_scale;
if (Convert.ToInt32(newHeight) > height && height > 0)
newHeight = Convert.ToDouble(height);
newWidth = Convert.ToInt32(newHeight * width_scale);
// Create PNG device with specified attributes
var pngDevice = new PngDevice(newWidth, Convert.ToInt32(newHeight), res);
// Convert a particular page and save the image to stream