简体   繁体   English

将docx转换成pdf

[英]Convert docx to pdf

My documents are stored in a database that I want to send mail with attachments. 我的文档存储在数据库中,该数据库要发送带有附件的邮件。

I want to convert stored docx to pdf. 我想将存储的docx转换为pdf。

var result = from c in valinor.documents
             select new
             {
                 c.document_name,
                 c.document_size,
                 c.document_content
             };

var kk = result.ToList();
for (int i = 0; i<kk.Count; i++)
{
    MemoryStream stream = new MemoryStream(kk[i].document_content);
    Attachment attachment = new Attachment(stream, kk[i].document_name + ".pdf", "application/pdf");
    mail.Attachments.Add(attachment);
}

How can I convert document_content to pdf? 如何将document_content转换为pdf?

You need to use Microsoft.Office.Interop.Word in MIcrosoft office dll. 您需要在MIcrosoft Office dll中使用Microsoft.Office.Interop.Word

  • add reference to your project Microsoft.Office.Interop.Word 添加对您的项目Microsoft.Office.Interop.Word引用
  • Check my sample of Code. 检查我的代码示例。

It's nice and Easy. 很好,很容易。 100% work for me. 100%为我工作。

Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();   
wordDocument = word.Documents.Open(savedFileName, ReadOnly: true);
wordDocument.ExportAsFixedFormat(attahcmentPath + "/pdf" + attachment.BetAttachmentCode + ".pdf", Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
word.Quit(false);

您将需要在计算机上安装第三方组件,例如ABCpdf和(可能)Word,然后使用该组件将docx转换为pdf。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM