简体   繁体   English

缩放图像以适合A4页面 - Migradoc

[英]Scale image to fit to A4 page - 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. 我有一系列图像,我想使用MigraDoc构建到PDF(1图像= 1页)每个图像必须显示在一个单独的页面上,但可能不会延伸到它必须完全适合页面的页面上。

So, how do I scale an image (of any size) to fit to a page using MigraDoc? 那么,如何使用MigraDoc缩放图像(任何大小)以适合页面?

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. 您调用AddImage()来添加图像 - 作为回报,您将获得一个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 . 您需要做的事情:检查图像的尺寸,计算哪个是限制因素(宽度或高度),然后在Image对象上设置此限制因子,并设置LockAspectRatio

Or set both Width and Height and leave LockAspectRatio off. 或者设置WidthHeight并关闭LockAspectRatio

For DIN A4, you may allow eg 19 cm x 27.7 cm as maximum image size. 对于DIN A4,您可以允许例如最大图像尺寸为19 cm x 27.7 cm。 For an image with 1000x1000 pixel you would set the width to 19 cm (assuming LockAspectRatio is on). 对于1000x1000像素的图像,您可以将宽度设置为19厘米(假设LockAspectRatio已打开)。 Height will then also be 19 cm automatically. 然后高度也将自动为19厘米。 For an image with 1000x2000 pixel you would set the height to 27.7 cm. 对于1000x2000像素的图像,您可以将高度设置为27.7厘米。 Width will then be 50% of the height. 宽度将是高度的50%。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM