0

我的文档存储在我想发送带有附件的邮件的数据库中。

我想将存储的 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);
}

我怎样才能转换document_content成pdf?

4

2 回答 2

1

您需要Microsoft.Office.Interop.Word在 MIcrosoft office 中使用 dll。

  • 添加对您的项目的引用Microsoft.Office.Interop.Word
  • 检查我的代码示例。

这很好,很容易。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);
于 2018-01-19T04:41:36.713 回答
0

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

于 2013-03-12T14:15:03.400 回答