关于Asp.Net调用Office组件将Word文件转换为Pdf文件
2020-12-13 04:21
标签:des blog class code c tar 1、首先安装 Microsoft Office 2007加载项:Microsoft Save as PDF-简体中文版:下载地址: http://download.microsoft.com/download/3/8/8/388812b2-0d3f-474e-a7ef-b095d3d0d3cd/SaveAsPDF.exe 关于Asp.Net调用Office组件将Word文件转换为Pdf文件,搜素材,soscw.com 关于Asp.Net调用Office组件将Word文件转换为Pdf文件 标签:des blog class code c tar 原文地址:http://www.cnblogs.com/taony/p/3732321.html
public
int
ConvertWordToPdfByPlugin(
string
sourceFilePath,
string
destFilePath)
{
int
result = 0;
object
paramMissing = Type.Missing;
Word.ApplicationClass wordApplication =
new
Word.ApplicationClass();
Word.Document wordDocument =
null
;
try
{
object
paramSourceFilePath = sourceFilePath;
Word.WdExportFormat paramExportFormat = Word.WdExportFormat.wdExportFormatPDF;
wordDocument = wordApplication.Documents.Open(
ref
paramSourceFilePath,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing,
ref
paramMissing);
if
(wordDocument !=
null
)
{
Word.WdExportOptimizeFor paramExportOptimizeFor =
Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument;
Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;
Word.WdExportCreateBookmarks paramCreateBookmarks =
Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
wordDocument.ExportAsFixedFormat(destFilePath,
paramExportFormat,
false
,
paramExportOptimizeFor, paramExportRange, 0,
0, paramExportItem,
true
,
true
, paramCreateBookmarks,
true
,
true
,
false
,
ref
paramMissing);
}
else
{
ScriptUtil.Alert(
"读取源word文件出错!"
);
}
}
catch
(Exception ex)
{
LogUtil.WriteLog(ex);
result = 1;
}
finally
{
if
(wordDocument !=
null
)
{
wordDocument.Close(
ref
paramMissing,
ref
paramMissing,
ref
paramMissing);
wordDocument =
null
;
}
if
(wordApplication !=
null
)
{
wordApplication.Quit(
ref
paramMissing,
ref
paramMissing,
ref
paramMissing);
wordApplication =
null
;
}
}
return
result;
}
文章标题:关于Asp.Net调用Office组件将Word文件转换为Pdf文件
文章链接:http://soscw.com/essay/29381.html