I am trying to display a user selected image on either a PDF or RTF document. I am using the same method to set up the document but somehow the RTF document comes out different in one way; non-square image's sizes do not render as specified. Bellow is the code I'm using to adjust the size of the image.
Originally I was only setting either the height or the width depending on which one was larger but in an RTF document the size was not coming out correct and I wanted to see what would happen if I set each explicitly. This did nothing to correct the problem.
using (System.Drawing.Image userImage = System.Drawing.Image.FromFile(userInfo.PicturePath)) { ImageOriginalHeight = userImage.Height; ImageOriginalWidth = userImage.Width; }
paragraph = row.Cells[0].AddParagraph(); paragraph.Format.SpaceAfter = 2; image = paragraph.AddImage(userInfo.PicturePath); image.LockAspectRatio = true; if (ImageOriginalHeight > ImageOriginalWidth) { image.Height = new Unit(0.73, UnitType.Inch); image.Width = new Unit((0.73 / (double)ImageOriginalHeight) * (double)ImageOriginalWidth, UnitType.Inch); } else if (ImageOriginalWidth > ImageOriginalHeight) { image.Width = new Unit(0.73, UnitType.Inch); image.Height = new Unit((0.73 / (double)ImageOriginalWidth) * (double)ImageOriginalHeight, UnitType.Inch); } else { image.Height = image.Width = new Unit(0.73, UnitType.Inch); }
|