PDFsharp & MigraDoc Foundation

Measure an image
Page 1 of 1

Author:  BrianTheK [ Thu Nov 29, 2018 5:21 am ]
Post subject:  Measure an image

Is there a way I can get the height of a paragraph containing text? The paragraph is added to a Section or a TextFrame. Or is the size not known until the document is rendered? I want to determine how much area is left so I can specify the size of an image so it fits on the page.

Speaking of the size of an image, when I add an image to a section or a frame and get an ImageObject back, is there a way I get the width and height of the image? The Width and Height attributes are not set at that point. I want to determine whether to adjust its width or height (only one) and have the image maintain its aspect ratio.

Author:  TH-Soft [ Thu Nov 29, 2018 7:49 am ]
Post subject:  Re: Measure an image

The size of a paragraph is unknown until it is rendered.

I'm not absolutely sure, but it could be that you have to open images with PDFsharp's XImage class to determine their size.

There are no public samples yet, but it is possible to add an empty paragraph at the end of the contents. After rendering the page with MigraDoc you can determine the position of the paragraph on the page and then draw the image in the size you need, e.g. as large as the remaining space allows.

Every MigraDoc object has a Tag member that you can set to any object. This allows to identify a paragraph after rendering.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group