How do I convert a PDF page to a fixed imagewidth?

Q: I have a problem resizing images, when converting from PDF to JPG.
I want to convert the page to a fixed imagewidth, for example 1000px.
I also want to have the height of the image scale automatically, but
without white space in the image-file.

If I use SetImageSize(1000, 1000, True), then I get whitespace on each
side of the page, in the jpg-file. If I omit the height-parameter (or
set it til 0), I get an error.

The dimentions of the pdf-file can vary from time to time, so I can
not hardcode the height. How can I achieve the desired result with
PDFnet?

I’ve also testet the ”same” funktion in the stand alone component
pdf2image.dll, and there the scaling works fine. But since we need
several functions, you recommended that we use PDFnet instead. So I
hope there is a solution.


A: You can calculate the aspect ratio of the input PDF page and use it
to calculate the variable dimension of the rasterized page. For
example:

// Generate an output image with a fixed with of ‘output_image_width’
pixels:
double pw = page.GetPageWidth();
double ph = page.GetPageHeight();
pdfdraw.SetImageSize(output_image_width, (int)(output_image_width * ph/
pw));

Similarly you can fix the height of the image:

// Generate an output image with a fixed height of
‘output_image_height’ pixels:
pdfdraw.SetImageSize((int)( output_image_height * pw/ph),
output_image_height);