|
PDFsharp - moved to http://forum.pdfsharp.net/ Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
|
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.
View previous topic :: View next topic |
Author |
Message |
blackjack2150
Joined: 21 Aug 2008 Posts: 5
|
Posted: Thu Aug 21, 2008 7:53 am Post subject: Adjust page size according to image size |
|
|
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 |
|
|
blackjack2150
Joined: 21 Aug 2008 Posts: 5
|
Posted: Thu Aug 21, 2008 11:14 am Post subject: |
|
|
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();
|
|
|
Back to top |
|
|
|
|
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
|
|