PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 8:00 am

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 Aug 21, 2008 7:53 am 
Offline

Joined: Thu Aug 21, 2008 7:23 am
Posts: 5
Hi.
I wrote a simple image to PDF converter using your library. I noticed that for some image files which are wide, they are trimmed and only the left side is visible in the PDF page produced.

So I decided to make an improvement and to make the PDF page to have the exact size of the source image. However, the effect is not what I expect it to be. The PDF page always comes out bigger than the initial image. I think that the measurement units are not the same, but I am not sure. Here is my code:

Code:
PdfDocument doc = new PdfDocument();
                doc.Pages.Add(new PdfPage());
                XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
                XImage img = XImage.FromFile(source);


                doc.Pages[0].Width = img.Size.Width;
                doc.Pages[0].Height = img.Size.Height ;
                                             
               
                xgr.DrawImage(img, 0, 0);
                doc.Save(destinaton);
                doc.Close();



How can I improve it, so that the PDF Page will have the exact size of the image?

Thanks.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 21, 2008 11:14 am 
Offline

Joined: Thu Aug 21, 2008 7:23 am
Posts: 5
Well I found the solution myself :). Here it is, in case anyone else has this issue:

Code:
PdfDocument doc = new PdfDocument();
doc.Pages.Add(new PdfPage());
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
XImage img = XImage.FromFile(source);

doc.Pages[0].Width = XUnit.FromPoint(img.Size.Width);
doc.Pages[0].Height = XUnit.FromPoint(img.Size.Height);
               
xgr.DrawImage(img, 0, 0, img.Size.Width, img.Size.Height);               

doc.Save(destinaton);
doc.Close();


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 393 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