PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Important Notice: We regret to inform you that our free phpBB forum hosting service will be discontinued by the end of June 30, 2024. If you wish to migrate to our paid hosting service, please contact billing@hostonnet.com.
Adjust page size according to image size

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
blackjack2150



Joined: 21 Aug 2008
Posts: 5

PostPosted: Thu Aug 21, 2008 7:53 am    Post subject: Adjust page size according to image size Reply with quote

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.
Back to top
View user's profile Send private message
blackjack2150



Joined: 21 Aug 2008
Posts: 5

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

Well I found the solution myself Smile. 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();
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com