Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm working on a project, the main goal of which is to generate a PDF to be generated and sent as an Email attachment.

A User Logs in/Registers..., then answers a set random of questions, and submits the answers.
The user is redirected to an asp page after this, which has the results as they have submitted.
Thing is I can print the Results into a pdf through the Gridview i.e.I can render the grid view data into a pdf doc with itextsharp, but the pdf is required to have images on certain positions, and at the same time, this pdf doc should not open or prompt for download, but should be sent to an email address of the user logged in?? Please help in VB or C#

SO far I have code that writes data rendered from the gridview into the PDF, but except images on the web page.

N.B- no images appear inside a gridview.
Posted
v3
Comments
You need to add codes so that we can modify.
Please click on "Improve question" link and post your codes.
Thanks...
woutercx 30-Jul-12 18:44pm    
I don't understand the sentence "SO far I have code that writes data rendered from the gridview into the PDF, but except images on the web page."
What do you mean bu "but except images on the web page"?

An article about working with images and iTextSharp:
It's about putting images at certain positions in a pdf with C#.

But couldn't you have found it using Google?

http://www.mikesdotnetting.com/Article/87/iTextSharp-Working-with-images[^]

About the other question you had: this pdf doc should not open or prompt for download, but should be sent to an email address of the user logged in; I show a couple of examples, your task is to pick the right pieces out of it to get it working.

-- Sending Email --

Simple SMTP E-Mail Sender in C#… Console application[^]

the SmtpClient is in the System.Net.Mail namespace.

An example can be found here:

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx[^]

-- Sending Email with pdf --

http://msdn.microsoft.com/en-us/library/system.net.mail.attachment.aspx[^]

and here

MailAddress from = new MailAddress(froma); 
MailAddress to = new MailAddress(email); 
MailMessage message = new MailMessage(from,to); 
SmtpClient client = new SmtpClient(); 
           
message.Subject = this.txtSubject.Text; 
               
message.IsBodyHtml = true; 
string attachmentPath = pdffile; 
System.Net.Mail.Attachment inline = new System.Net.Mail.Attachment(attachmentPath, MediaTypeNames.Application.Pdf); 
inline.ContentDisposition.Inline = true; 
inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline; 
inline.ContentType.MediaType = MediaTypeNames.Application.Pdf; 
inline.ContentType.Name = Path.GetFileName(attachmentPath); 
message.Attachments.Add(inline); 
  
client.Host = Session["smtp"].ToString(); 
client.Port = Convert.ToInt32(Session["port"].ToString()); 
client.Send(message); 
 
Share this answer
 
v6
Hello .
Recently i develop a web service that generate a PDf
the first step is to load an image in png format with graphics class . then write the datagridview data over the png . and then load with itextsharp the image (bytes) and save in pdf format .
This way is very very good cause the result is smaller than pdf with javascript fields
So far i only tell you how you can perform your project
regards from.mexico
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900