Fit image onto one PDF page using MigraDoc

两盒软妹~` 提交于 2020-12-10 06:32:02

问题


I am able to easily add an image to a section in the PDF file with MigraDoc. However, the image is cut in half by the page width.

Is there a way to force the picture to resize so that it completely fits on one page? Or must this be done manually?

If it has to be done manually, does anyone know the dimensions of a PDF page in MigraDoc?


回答1:


The image will be drawn in the size you set for the image.

Image image = section.Headers.Primary.AddImage("../../PowerBooks.png");
image.Width = "2.5cm";
image.LockAspectRatio = true;

This snippet sets the width. The height will be adjusted proportionally because LockAspectRatio was set. You can set both height and width, but then the aspect ratio won't be kept.

There is no trick like "100%" to get the full page width, but that is not needed IMHO. The page width can always be calculated from the PageSetup of the section.

The standard page size is DIN A4. Width is 21 cm, height is 29.7 cm. Many other pre-defined page sizes are also available. And custom page sizes can also be used. See the PageSetup property of your section.

Have you checked the samples that come with MigraDoc? You can also see them here:
http://pdfsharp.net/wiki/Invoice-sample.ashx



来源:https://stackoverflow.com/questions/31301226/fit-image-onto-one-pdf-page-using-migradoc

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