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 

Put an image into pdf file

 
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
njuliard



Joined: 03 Jul 2007
Posts: 4

PostPosted: Tue Jul 03, 2007 12:43 pm    Post subject: Put an image into pdf file Reply with quote

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



Joined: 03 Jul 2007
Posts: 4

PostPosted: Wed Jul 04, 2007 8:23 am    Post subject: Finally I've found the answer by myself Reply with quote

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



Joined: 04 Mar 2008
Posts: 8

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

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!
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Thu Mar 06, 2008 8:03 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
edmicman



Joined: 04 Mar 2008
Posts: 8

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

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 Smile

Great job on the library!
Back to top
View user's profile Send private message
dalebert



Joined: 03 Apr 2009
Posts: 2

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

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



Joined: 03 Apr 2009
Posts: 2

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

Nevermind, I got it figured out.

Thanks anyway...
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