PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Jul 13, 2024 11:03 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Oct 06, 2011 8:29 pm 
Offline

Joined: Thu Oct 06, 2011 8:10 pm
Posts: 1
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); }


Top
 Profile  
Reply with quote  
PostPosted: Sat Oct 08, 2011 10:24 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 343
Hi!

Just a wild guess: Do not use "image.LockAspectRatio = true;" if you want to set height and width explicitly.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 78 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group