问题
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