PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Add an image with MigraDoc that is scaled to margins
http://forum.pdfsharp.com/viewtopic.php?f=2&t=3876
Page 1 of 1

Author:  BrianTheK [ Sat Nov 24, 2018 6:50 pm ]
Post subject:  Add an image with MigraDoc that is scaled to margins

How can I add add an image with MigraDoc that is scaled (with aspect ratio) to fit within the margins of the page? Can I add it from a stream, after I manipulate the image myself? I don't want to write it to a file, just to use section.AddImage() with a file name. I believe i saw some "enhanced packages" that uses streams for images, but I'd rather use the "official" release. I have 1.50.4845-RC2a. Nice library by the way.

Author:  TH-Soft [ Sun Nov 25, 2018 10:22 am ]
Post subject:  Re: Add an image with MigraDoc that is scaled to margins

BrianTheK wrote:
How can I add add an image with MigraDoc that is scaled (with aspect ratio) to fit within the margins of the page?
Do some simple maths, then draw the image with the suitable size. You just have to find whether height or width is the limiting aspect.

BrianTheK wrote:
Can I add it from a stream, after I manipulate the image myself?
You can use files from BASE64-encoded strings, but there is no need to manipulate the image file if you just want to draw an image with a specific size.

Author:  BrianTheK [ Sun Nov 25, 2018 9:38 pm ]
Post subject:  Re: Add an image with MigraDoc that is scaled to margins

I found out that Section.AddImage() returns a MigraDoc.DocumentObjectModel.Shapes.Image object and that I can do
Image.LockAspectRatio = true;
Image.Width = 300; // points

To set the size of the image.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/