<%@ Import
Namespace="System.Web" %> <%@ Import
Namespace="System.Web.Mail" %> <%@ Import
Namespace="System.Reflection" %> <%@ Import
Namespace="ASPPDFLib" %> <script
runat="server" LANGUAGE="C#"> void Send(Object
Source, EventArgs E) { try { // create instance of
the PDF manager IPdfManager objPDF; objPDF = new PdfManager(); // Create new document IPdfDocument objDoc =
objPDF.CreateDocument(Missing.Value); // Add a page to
document IPdfPage objPage =
objDoc.Pages.Add(Missing.Value, Missing.Value, Missing.Value); // We will use Arial font which
supports many alphabets. // Use another font if you Arial does
not support your language (such as Chinese) IPdfFont objFont =
objDoc.Fonts["Arial", Missing.Value]; // create a parameter
object IPdfParam objParam =
objPDF.CreateParam("size=20; expand=true"); // Create table with 4
rows and 2 columns, no border.
Initial height not important. IPdfTable objTable =
objDoc.CreateTable("width=500; height=20; Rows=4; Cols=2; Border=0;
CellBorder=0; CellSpacing=-1; cellpadding=2 "); objTable.Font = objFont; // Make left column smaller objTable.Rows[1].Cells[1].Width = 100; objTable.Rows[1].Cells[2].Width = 400; objTable.Rows[1].Cells[1].AddText(
"From:", objParam, Missing.Value ); objTable.Rows[1].Cells[2].AddText(
"AspPDF Live Demo", objParam, Missing.Value ); objTable.Rows[2].Cells[1].AddText(
"To:", objParam, Missing.Value ); objTable.Rows[2].Cells[2].AddText(
txtEmail.Value, objParam, Missing.Value ); objTable.Rows[3].Cells[1].AddText(
"Subject:", objParam, Missing.Value ); objTable.Rows[3].Cells[2].AddText(
txtSubject.Value, objParam, Missing.Value ); objTable.Rows[4].Cells[1].AddText(
"Message:", objParam, Missing.Value ); objTable.Rows[4].Cells[2].AddText(
txtBody.Value, objParam, Missing.Value ); objTable.Rows[4].Cells[2].BgColor =
"lightgray"; // Render table on page objPage.Canvas.DrawTable( objTable,
"x=50; y=750" ); // Now handle
attachments. Use "FileAttachment" annotations ListDictionary arrPaths =
(ListDictionary)Session["arrPaths"]; ListDictionary arrNames =
(ListDictionary)Session["arrNames"]; int i = 0; foreach( int key in arrNames.Keys ) { // x, y, width, height are
coordinates of the paperclip icon objParam.Set(
"Type=FileAttachment; y=760;width=10; height=10" ); objParam["x"].Value =
10 + 30 * i; String strName = (String)arrNames[key]; IPdfAnnot objAnnot =
objPage.Annots.Add( strName, objParam, "PaperClip", arrPaths[key]
); i++; } // Encrypt document with
password, use 128-bit key. Permission flags not used. objDoc.Encrypt( "",
txtPwd.Text, 128, Missing.Value ); String strFilename = objDoc.Save(
Server.MapPath("files") + "\\message.pdf", false ); // Document created. Now
send it via email as an attachment MailMessage objMail = new
MailMessage(); objMail.From = "AspPDF Live Demo
<info@asp-pdf.com>"; objMail.To = txtEmail.Value; objMail.Body = "Open PDF
attachment to read the message."; objMail.Subject = "Secure message
from AspPDF live demo"; objMail.Attachments.Add( new
System.Web.Mail.MailAttachment( Server.MapPath("files") +
"\\" + strFilename ) ); SmtpMail.SmtpServer =
"amsterdam"; SmtpMail.Send( objMail ); lblResult.Text = "<font
color=\"green\">Success! A message was sent to <i>" +
txtEmail.Value + "</i></font>."; } catch(Exception e) { lblResult.Text = "<font
color=\"red\">Error: " + e.Message + "</font>"; } } </script> |