如何在.pdf文件中转换ck编辑器内容并将其附加到邮件中 [英] How to convert ck editor content in .pdf file and attach it with mail

查看:78
本文介绍了如何在.pdf文件中转换ck编辑器内容并将其附加到邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..朋友,



在我的网络应用程序中有一个发票页面......发票格式在CK编辑器中。



在提交按钮时,我想将信息保存在数据库中,并以.pdf格式转换CK内容并附上邮件。因此我可以通过邮件将发票作为附件以.pdf格式发送给客户....





嗨...全部



我已经通过内存流使用iTextsharp.dll动态转换了CK内容,它将内容转换为pdf并成功将其附加到邮件中但是当我下载发票pdf时邮件已下载但未打开。它显示错误,如打开此文档时出错。文件已损坏且无法修复。



我使用了以下代码(称为函数)按钮点击):







 private void SendMail()
{
#region转换pdf内存流中的ck内容的代码

MemoryStream mstream = new MemoryStream();
文件文件=新文件(PageSize.A4,20f,20f,20f,20f);
PdfWriter writer = PdfWriter.GetInstance(document,mstream);



document.Open();
document.Add(新段落(INVOICE));

document.Add(new Paragraph(txt_invoice.Text));

#endregion


string mailTo = txt_mailTo.Text.Trim()。Replace(','').ToString();


string msgSubject = txt_mailSubject.Text.ToString();
string msgBody =此发票是由影响的infomedia服务为您生成的;

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(xxxxxxxxxxxx.in,mailTo,msgSubject,msgBody);

mstream.Position = 0;
mail.Attachments.Add(new Attachment(mstream,Invoice.pdf));

mail.IsBodyHtml = true;
SmtpClient客户端=新的SmtpClient();
client.Host =主机名在这里;
client.Port = 25;
client.Credentials = new NetworkCredential(xxxxxxxxxxx,xxxxxxxxxxxx);
client.Send(mail);

document.Close();
mstream.Flush();
mstream.Close();


lbl_msg.Visible = true;
lbl_msg.Text =电子邮件已成功发送;
lbl_msg.ForeColor = System.Drawing.Color.Green;
txt_mailSubject.Text =;
txt_mailTo.Text =;
}







请追踪我的错误或帮助我......

解决方案

您可以使用ITextsharp dll并将其用于将HTML转换为PDF格式。







 <   a     href   =  http://www.codeproject.com/Questions/341142/itextsharp-read-pdf-file >  itextsharp阅读pdf文件< span class =code-keyword><   / a  >  [<   a     href   =  http://www.codeproject.com/Questions / 341142 / itextsharp-read-pdf-file    target   =  _ blank    title   = 新窗口 >  ^ <   / a  > ] 
< a href = http:// www。 codeproject.com/Articles/686994/Create-Read-Advance-PDF-Report-using-iTextSharp-in\"> 创建/阅读高级PDF报告在C#.NET中使用iTextSharp:第一部分< / a > [< a href = http://www.codeproject.com/Articles/686994/Create-Read-Advance-PDF-Report-using-iTextSharp-in target = _blank title = 新窗口 > ^ < / a > ]
< ; a href = http://www.codeproject.com/Questions/645392/Extract-逐行-PDF-using-iTextSharp-csh > 使用iTextSharp c#< / a > [< a href = http://www.codeproject.com/Questions/645392/Extract-text-by- line-from-PDF-using-iTextSharp-csh target = _ blank title = 新窗口 > ^ < / a > ]
< a href = http://www.codeproject.com/Questions/168290/PDF-Document-Reading-in-C-net-using-itext-sharp > 使用itext sharp在C#.net中读取PDF文档。< / a > [< a href = http://www.codeproject.com/Questions/168290/PDF-Document-Reading-in-C -net-using-itext-sharp target = _ blank title = 新窗口 > ^ < / a >


Hi..Friends,

In my web application there is a page for invoicing...The invoice format is in CK Editor.

At submit button i want to save the information in database and convert the CK content in .pdf format and attach it with mail. So that i can send invoice to clients through mail as an attachment in .pdf format....


Hi...All

I have converted CK content dynamically using iTextsharp.dll through the memory stream, It converts content into pdf and successfully attach it with mail but when i download the invoice pdf from mail it downloaded but not opened. It shows the error like "There was an error opening this document. The file is damaged and could not be repaired."

I have used following code (called the function at button click) :



private void SendMail()
    {
        #region Code to convert ck content in pdf memory stream

        MemoryStream mstream = new MemoryStream();
        Document document = new Document(PageSize.A4, 20f, 20f, 20f, 20f);
        PdfWriter writer = PdfWriter.GetInstance(document, mstream);



        document.Open();
        document.Add(new Paragraph("INVOICE"));

        document.Add(new Paragraph(txt_invoice.Text));

        #endregion


        string mailTo = txt_mailTo.Text.Trim().Replace("'", "''").ToString();


        string msgSubject = txt_mailSubject.Text.ToString();
        string msgBody = "This invoice is generated for you by impact infomedia services";

        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage("xxxxxxxxxxxx.in", mailTo, msgSubject, msgBody);

        mstream.Position = 0;
        mail.Attachments.Add(new Attachment(mstream, "Invoice.pdf"));

        mail.IsBodyHtml = true;
        SmtpClient client = new SmtpClient();
        client.Host = "host name is here";
        client.Port = 25;
        client.Credentials = new NetworkCredential("xxxxxxxxxxx", "xxxxxxxxxxxx");
        client.Send(mail);

        document.Close();
        mstream.Flush();
        mstream.Close();


        lbl_msg.Visible = true;
        lbl_msg.Text = "E-mail has been sent successfully";
        lbl_msg.ForeColor = System.Drawing.Color.Green;
        txt_mailSubject.Text = "";
        txt_mailTo.Text = "";
    }




Please trace my error or help me...

解决方案

you can use ITextsharp dll and use it for converting HTML to PDF.



<a href="http://www.codeproject.com/Questions/341142/itextsharp-read-pdf-file">itextsharp read pdf file</a>[<a href="http://www.codeproject.com/Questions/341142/itextsharp-read-pdf-file" target="_blank" title="New Window">^</a>]
<a href="http://www.codeproject.com/Articles/686994/Create-Read-Advance-PDF-Report-using-iTextSharp-in">Create/Read Advance PDF Report using iTextSharp in C# .NET: Part I</a>[<a href="http://www.codeproject.com/Articles/686994/Create-Read-Advance-PDF-Report-using-iTextSharp-in" target="_blank" title="New Window">^</a>]
<a href="http://www.codeproject.com/Questions/645392/Extract-text-by-line-from-PDF-using-iTextSharp-csh">Extract text by line from PDF using iTextSharp c#</a>[<a href="http://www.codeproject.com/Questions/645392/Extract-text-by-line-from-PDF-using-iTextSharp-csh" target="_blank" title="New Window">^</a>]
<a href="http://www.codeproject.com/Questions/168290/PDF-Document-Reading-in-C-net-using-itext-sharp">PDF Document Reading in C#.net using itext sharp.</a>[<a href="http://www.codeproject.com/Questions/168290/PDF-Document-Reading-in-C-net-using-itext-sharp" target="_blank" title="New Window">^</a>]


这篇关于如何在.pdf文件中转换ck编辑器内容并将其附加到邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆