0

We're using migradoc api to create an rtf document.. intermittently when we add an image it;s being resized and coming out absolutely tiny.

Code sample as follows:

MigraDoc.DocumentObjectModel.Shapes.Image image = section.AddImage(imagePath);
image.WrapFormat.Style = MigraDoc.DocumentObjectModel.Shapes.WrapStyle.Through;

If I set LockAspectRatio to true and set a width it does stop is from rendering very small but ideally would like to be able to set a MaxWidth.

Has anyone experiences similar issue?

Tom Miller
  • 431
  • 1
  • 5
  • 16
  • 1
    Have you checked the DPI of the image in addition to its pixel size? – TaW Jul 16 '14 at 10:41
  • @TaW The original image with the problem has 300 dpi x 300 dpi and 100px x 100px. Strange - when I copy the image and re-save it in Paint (the most advanced image tool) it doesn't come out tiny this time. But when I view the file properties it doesn't show the DPI on the new file. – Tom Miller Jul 16 '14 at 10:56
  • 1
    PDF is respecting DPIs. So 100px with 300dpi will result in 1/3 of an inch. Calculate the size you want and set the dpi accordingly. – TaW Jul 16 '14 at 11:12

2 Answers2

2

You have a choice of either changing the image itself by storing a different DPI value in it.

The .Net command to do so with a Bitmap bmp is:

bmp.SetResolution(newHRes , newVRes);

This should not involve reencoding, but I'm not sure.

However you also can simply set the desired DPI value in the Migradoc Image by using its Image.Resolution Property, which

Gets or sets a user defined resolution for the image in dots per inch.

TaW
  • 53,122
  • 8
  • 69
  • 111
0

I am not familiar with it at all but I found this code that might help you :

image.RelativeVertical = RelativeVertical.Page;
image.RelativeHorizontal = RelativeHorizontal.Page;
Zardaloop
  • 1,594
  • 5
  • 22
  • 43