Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale image to fit to A4 page - Migradoc

Tags:

c#

migradoc

I am really struggling to get this right, any help would be appreciated.

I have a series of images that I want to build in to a PDF using MigraDoc (1 image = 1 page) Each image must be displayed on a separate page but may not extend over the page it must fit on to the page perfectly.

So, how do I scale an image (of any size) to fit to a page using MigraDoc?

like image 975
msbarnard Avatar asked Oct 09 '14 08:10

msbarnard


1 Answers

You call AddImage() to add the image - and in return you get an Image object that allows you to set width and/or height of the image.

What you have to do: check the dimensions of the image, calculate which is the limiting factor (width or height), then set this limiting factor on the Image object and also set LockAspectRatio.

Or set both Width and Height and leave LockAspectRatio off.

For DIN A4, you may allow e.g. 19 cm x 27.7 cm as maximum image size. For an image with 1000x1000 pixel you would set the width to 19 cm (assuming LockAspectRatio is on). Height will then also be 19 cm automatically. For an image with 1000x2000 pixel you would set the height to 27.7 cm. Width will then be 50% of the height.

like image 92
I liked the old Stack Overflow Avatar answered Nov 10 '22 07:11

I liked the old Stack Overflow