如何在 C# 中将 .docx 转换为 .pdf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19560170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 15:17:52  来源:igfitidea点击:

How to convert .docx to .pdf in C#

c#file-conversion

提问by Robin Sun

Now we are using OpenXML to read data from database and generate doc. But the final requirement is to be a pdf. So I want to know how to convert .docx to pdf in C#. Could anyone for help? Or provide some information.

现在我们使用 OpenXML 从数据库中读取数据并生成文档。但最终要求是pdf。所以我想知道如何在 C# 中将 .docx 转换为 pdf。有人可以帮忙吗?或者提供一些信息。

采纳答案by Demir

You can check solutions in this link: http://www.codeproject.com/Questions/346784/How-to-convert-word-document-to-pdf-in-Csharp

您可以在此链接中查看解决方案:http: //www.codeproject.com/Questions/346784/How-to-convert-word-document-to-pdf-in-Csharp

I recommend using this among solutions as first:

我建议首先在解决方案中使用它:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Office.Interop.Word;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
        wordDocument = appWord.Documents.Open(@"D:\desktop\xxxxxx.docx");
        wordDocument.ExportAsFixedFormat(@"D:\desktop\DocTo.pdf", WdExportFormat.wdExportFormatPDF);
    }

    public Microsoft.Office.Interop.Word.Document wordDocument { get; set; }
}

回答by Yao Bo Lu

You could take a look at libraries like iTextSharp

你可以看看像iTextSharp这样的库