PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue Jul 03, 2007 12:43 pm 
Offline

Joined: Tue Jul 03, 2007 12:34 pm
Posts: 4
Hi everybody,

I would like to create pdf files with JPEG images inside. How do I need to proceed ?
For more informations, my pdf file is automatically generated from a website thanks to a web form.

Thanks in advance,

Nicolas


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 04, 2007 8:23 am 
Offline

Joined: Tue Jul 03, 2007 12:34 pm
Posts: 4
Code:
PdfSharp.Drawing.XImage image = PdfSharp.Drawing.XImage.FromFile(@".\images\image.jpg");
double width = image.Width;
double height = image.Height;
width.GetType();
height.GetType();
gfx.DrawImage(image, 100, 100);


Have a nice day,

Nicolas


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Mar 05, 2008 5:06 pm 
Offline

Joined: Tue Mar 04, 2008 3:31 pm
Posts: 8
Can you post your full code to add a jpg image to create a PDF? I have 1 or more JPG images that I would like to "output" to a single PDF in memory, that can be viewed on the web. I don't want to save the PDF, just want to create it on the fly if a user clicks a link.

I tried something like this:
Code:
PdfSharp.Drawing.XImage image = PdfSharp.Drawing.XImage.FromFile(FullFilename);
                            double width = image.Width;
                            double height = image.Height;
                            width.GetType();
                            height.GetType();
                            PdfSharp.Drawing.XGraphics gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(page);
                            gfx.DrawImage(image, width, height);


but that didn't work. I had been working with the FileStream to load my image, then loading that into a MemoryStream to try and get the PDF document to save it, but I'm just getting a blank PDF now. Any help would be greatly appreciated!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Mar 06, 2008 8:03 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
edmicman wrote:
[...] but I'm just getting a blank PDF now.

Without checking your code, I'd say that your variables width and height contain the image dimensions in Pixel, while the DrawImage method requires the position to draw at in Points.
Small images will be drawn on the page, larger images will be drawn outside the page (DIN A4 is 595 by 842 points in size).
You'll get better results if you stick with the position (100, 100) from the sample above.

There should be versions of DrawImage that take both position and size - I guess this is what you're looking for.

BTW: the calls to GetType() are not required - they're only good for breakpoints ...

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Mar 06, 2008 2:47 pm 
Offline

Joined: Tue Mar 04, 2008 3:31 pm
Posts: 8
Thank you! I did end up getting it working....my images are displaying, and I can get them to display in the size I want. Now I just have to work on getting a better source image so it doesn't lose as much quality when I increase the size :-)

Great job on the library!


Top
 Profile  
Reply with quote  
 Post subject: clarification
PostPosted: Fri Apr 03, 2009 5:02 pm 
Offline

Joined: Fri Apr 03, 2009 4:58 pm
Posts: 2
Hello,

I was hoping I could get some clarification on the code "edmicman" provided.

In the last line (gfx.DrawImage(image, width, height);), what does the "gfx" refer to?

I'm trying to use this as a guideline for adding a graphic to my PDF's and in my .net web form (in VB) it needs to be declared and I'm not sure what data type it's supposed to be.

Can someone enlighten me?

Thanks.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Apr 03, 2009 5:17 pm 
Offline

Joined: Fri Apr 03, 2009 4:58 pm
Posts: 2
Nevermind, I got it figured out.

Thanks anyway...


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 394 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