Scale image to fit to A4 page - Migradoc

我怕爱的太早我们不能终老 提交于 2019-12-07 01:34:21

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/26274245/scale-image-to-fit-to-a4-page-migradoc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!