【发布时间】:2013-12-04 09:39:17
【问题描述】:
在 Web 应用程序中,我必须实现一种将 doc/docx 转换为 PDF 的方法。我就是这样做的:
FileInfo FILE = new FileInfo(path + filename);
object missing = System.Reflection.Missing.Value;
object readOnly = false;
object objfilename = (object)FILE;
//Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
try
{
Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
// var wordDocument = appWord.Documents.Open(FILE);
var wordDocument = appWord.Documents.Open(ref objfilename,
ref missing, ref readOnly, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing);
wordDocument.ExportAsFixedFormat(@"C:\Users\ABCD\Desktop\New folder\DocTo.pdf", WdExportFormat.wdExportFormatPDF);
但是 Documents.Open 行上的代码中断并且它显示的错误是:
[System.Runtime.InteropServices.COMException] = {"类型不匹配。(来自 HRESULT 的异常:0x80020005 (DISP_E_TYPEMISMATCH))"}
【问题讨论】:
-
@MitchWheat:您能否分享一些关于我应该如何使用 iText 将内存流(word doc/docx)转换为 pdf 的代码。这将非常有帮助。
-
另外我有一个现有的文档,我认为 iText 不会有帮助http://stackoverflow.com/questions/1537063/itextsharp-convert-word-doc-docx-to-pdf
-
convert doc to pdf in c# 的可能重复项