Image Scale Fit for A4 Page - Migradoc

I'm really trying to get it right, any help would be appreciated.

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

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

+5
source share
1 answer

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

What you need to do: check the image size, calculate which limiting factor (width or height), then set this limiting factor for the Image object, and set LockAspectRatio .

Or set both Width and Height and leave LockAspectRatio off.

For DIN A4, you can allow, for example, 19 cm x 27.7 cm as the maximum image size. For an image with a size of 1000x1000 pixels, you must set the width to 19 cm (provided that LockAspectRatio enabled). The height will also be automatically 19 cm. For an image with a resolution of 1000x2000 pixels, you must set the height to 27.7 cm. Then the width will be 50% of the height.

+14
source

Source: https://habr.com/ru/post/1204313/


All Articles