PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jul 15, 2024 7:42 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Resize image in MigraDoc
PostPosted: Mon Nov 23, 2009 10:40 am 
Offline

Joined: Wed Nov 18, 2009 5:37 pm
Posts: 7
Hi,

I am adding an image in Document using MigraDoc.
The dimension of the image is 771 X 1470.

1) How can i scale the image to a predefined size?

I am writing ...

MigraDoc.DocumentObjectModel.Shapes.Image img = ReceiptsPara.AddImage("D:\\abc.jpg");
img.LockAspectRatio = false;
img.Width = new Unit(300, UnitType.Point); ;
img.Height = new Unit(300, UnitType.Point);
ReceiptsPara.AddLineBreak();

but it causes the application to hang.

2) If i add an image 2 times the application hangs

ReceiptsPara.AddImage("D:\\abc.jpg");
ReceiptsPara.AddImage("D:\\xyz.jpg");
ReceiptsPara.AddImage("D:\\abc.jpg");

Is there any thing wrong i am doing? Or am i missing anything?
Hope to hear soon.

Thanks in advance


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 23, 2009 10:46 am 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi,

when I have resized images - i used the XImage.ScaleHeight/ScaleWidth property and I didnt encounter any difficulties? I was using vector graphics though.

Mike


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 23, 2009 11:40 am 
Offline

Joined: Wed Nov 18, 2009 5:37 pm
Posts: 7
Hi Mike,

Excuse me if i am wrong, i am new to MigraDoc.
XImage is part of PdfSharp and i am using only MigraDoc.
How can i use XImage in MigraDoc.

My problem is I have image files to be added in Pdf document. And while adding image, i want the images to get resized to best fit a specified dimension say for e.g. 500 X 500.


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 23, 2009 12:19 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Hi!
VibhoreBenjamin wrote:
And while adding image, i want the images to get resized to best fit a specified dimension say for e.g. 500 X 500.

This can be done using the Image object of MigraDoc.

If you don't need the power of MigraDoc, then use PDFsharp only and work with XImage objects.

If certain images cause the application to hang, then please provide us with these images and also specify whether you are using the WPF or the GDI+ build.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 23, 2009 12:37 pm 
Offline

Joined: Wed Nov 18, 2009 5:37 pm
Posts: 7
Hi,

I am using MigraDoc GDI+ build.

I want the image to best fit (maintaining the aspect ratio) in 500 X 300 rectangle. To achieve this i am doing

MigraDoc.DocumentObjectModel.Shapes.Image img = ReceiptsPara.AddImage("C:\\abc.jpg");
img.LockAspectRatio = true;
img.Width = Unit.FromPoint(500);
img.Height = Unit.FromPoint(300);

The image gets fit into the specified dimension, but the ratio gets distorted. My requirement is that the image's aspect ratio should remain as it is and still should best fit in the specified dimension.


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 23, 2009 5:09 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
It's not a bug, it's a feature:
Quote:
Image.LockAspectRatio Property:
Gets or sets whether the AspectRatio of the image is kept unchanged. If both Width and Height are set, this property is ignored.


Calculate the height for a width of 500, and calculate the width for a height of 300, and then use the smaller rectangle to draw the image.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 24, 2009 3:01 pm 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
XImage was a type in my earlier post - the same ScaleHeight/Width functions can be used on MigraDoc Image object.

Also, surely locking the aspect ratio, then setting just one of the properties i.e. width would do the trick?

Mike


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 24, 2009 3:56 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
mikesowerbutts wrote:
Also, surely locking the aspect ratio, then setting just one of the properties i.e. width would do the trick?

Yes.
But you'll lose if you e. g. have landscape and portrait photos and a square to show them in ...

It would make sense to allow LockAspectRatio if both Width and Height are set ...
Maybe I'll put that on our wish list.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 11, 2010 10:10 am 
Offline

Joined: Thu Nov 11, 2010 10:03 am
Posts: 7
Quote:
If you don't need the power of MigraDoc, then use PDFsharp only and work with XImage objects.


Hello
I do not see any ScaleHeight/Width Method on the XImage class
For now I'm doing it manualy whith a

Code:
DrawImage(Image,DstRect,SrcRect,GraphicsUnit);


The problem to avoid to get too big images in the document is that I have to do it twice
Once to Hard Resize the image to a new one
Then to effectively drraw the resized image on the Document

Is there any better way ?

Thanks for any help


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 59 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group