c# office转换成pdf
//将word文档转换成PDF格式
private bool Convert(string sourcePath, string targetPath, Word.WdExportFormat exportFormat)
{
bool result;
object paramMissing = Type.Missing;
Word.ApplicationClass wordApplication = new Word.ApplicationClass();
Word.Document wordDocument = null;
try
{
object paramSourceDocPath = sourcePath;
string paramExportFilePath = targetPath; Word.WdExportFormat paramExportFormat = exportFormat;
bool paramOpenAfterExport = false;
Word.WdExportOptimizeFor paramExportOptimizeFor =
Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument;
int paramStartPage = 0;
int paramEndPage = 0;
Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;
bool paramIncludeDocProps = true;
bool paramKeepIRM = true;
Word.WdExportCreateBookmarks paramCreateBookmarks =
Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
bool paramDocStructureTags = true;
bool paramBitmapMissingFonts = true;
bool paramUseISO19005_1 = false; wordDocument = wordApplication.Documents.Open(
ref paramSourceDocPath, 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)
wordDocument.ExportAsFixedFormat(paramExportFilePath,
paramExportFormat, paramOpenAfterExport,
paramExportOptimizeFor, paramExportRange, paramStartPage,
paramEndPage, paramExportItem, paramIncludeDocProps,
paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
paramBitmapMissingFonts, paramUseISO19005_1,
ref paramMissing);
result = true;
}
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;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
return result;
} //将excel文档转换成PDF格式
private bool Convert(string sourcePath, string targetPath, XlFixedFormatType targetType)
{
bool result;
object missing = Type.Missing;
Excel.ApplicationClass application = null;
Workbook workBook = null;
try
{
application = new Excel.ApplicationClass();
object target = targetPath;
object type = targetType;
workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing); workBook.ExportAsFixedFormat(targetType, target, XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
result = true;
}
catch
{
result = false;
}
finally
{
if (workBook != null)
{
workBook.Close(true, missing, missing);
workBook = null;
}
if (application != null)
{
application.Quit();
application = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
return result;
} //将ppt文档转换成PDF格式
private bool Convert(string sourcePath, string targetPath, PpSaveAsFileType targetFileType)
{
bool result;
object missing = Type.Missing;
PowerPoint.ApplicationClass application = null;
Presentation persentation = null;
try
{
application = new PowerPoint.ApplicationClass();
persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue); result = true;
}
catch
{
result = false;
}
finally
{
if (persentation != null)
{
persentation.Close();
persentation = null;
}
if (application != null)
{
application.Quit();
application = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
return result;
}
- 在组件服务中添加权限
Microsoft Access 2000/2002 - Microsoft Access 应用程序
Microsoft Excel 97/2000/2002 - Microsoft Excel 应用程序
Microsoft Word 97 - Microsoft Word Basic
Microsoft Word 2000/2002 - Microsoft Word 文档
单击属性打开此应用程序的属性对话框。
1)标示—运行此应用程序的用户账户—下列用户;然后输入Administrator用户组中的一个用户。
注:更改服务器中组件服务所用到的用户密码时,须在组件中重新输入新的密码,才能正常生成Word。
2)安全—启动和激活权限,选择“自定义”,添加IIS_WPG用户的本地启动、本地激活权限;
3)安全—访问权限,选择“自定义”,添加IIS_WPG用户的本地访问权限;
c# office转换成pdf的更多相关文章
- java-使用Jacob实现office转换成pdf
参考路径: https://blog.csdn.net/csdnFlyFun/article/details/79523262#commentBox Jacob组件下载地址:https://sourc ...
- office转换成pdf
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import j ...
- 关于office转换成pdf组件服务中的DCOM配置问题
在开始->运行 中录入“dcomcnfg” 单击“确定”后弹出“组件服务”窗口 依次选择“组件服务”->“计算机”->“我的电脑”->“DCOM配置” 在“DCOM配置”下找到 ...
- C#将Word转换成PDF方法总结(基于Office和WPS两种方案)
有时候,我们需要在线上预览word文档,当然我们可以用NPOI抽出Word中的文字和表格,然后显示到网页上面,但是这样会丢失掉Word中原有的格式和图片.一个比较好的办法就是将word转换成pdf,然 ...
- 服务器端打开office然后采用虚拟打印 转换成pdf
服务器端打开office然后采用虚拟打印 转换成pdf [WebMethod] public bool ConvertWordTOPDF(string WordPath) { bool ret=fal ...
- java调用com组件将office文件转换成pdf
在非常多企业级应用中都涉及到将office图片转换成pdf进行保存或者公布的场景,由于pdf格式的文档方便进行加密和权限控制(类似于百度文库).总结起来眼下将office文件转换 成pdf的方法主要有 ...
- ABBYY如何把图片转换成pdf格式
在制作工作文件的时候,有时候会遇到需要进行文件格式转换的情况,比较常见的文件格式转换就包含了Office与pdf格式之间的转换.但除此之外,图片与pdf格式也是可以进行转换的,那么图片要怎么操作,才能 ...
- ASP.NET将word文档转换成pdf的代码
一.添加引用 using Microsoft.Office.Interop.Word; 二.转换方法 1.方法 C# 代码 /// <summary> /// 把Word文件转换成pdf文 ...
- word ppt excel文档转换成pdf
1.把word文档转换成pdf (1).添加引用 using Microsoft.Office.Interop.Word; 添加引用 (2).转换方法 /// <summary> /// ...
随机推荐
- B/S、C/S区别
[B/S.C/S C/S (Client/Server客户端服务器) B/S (Brower/Server浏览器服务器) 区别 1.硬件环境不同: C/S 一般建立在专用的网络上, 小范围里的网络环 ...
- C/C++中define定义的常量与const常量
常量是在程序中不能更改的量,在C/C++中有两种方式定义常量,一种是利用define宏定义的方式,一种是C++中新提出来的const型常变量,下面主要讨论它们之间的相关问题: define定义的常量: ...
- 分布式版本控制系统Git-----5.Git 的push命令总结
git push git push命令用于将本地分支的更新,推送到远程主机.它的格式与git pull命令相仿. git push <远程主机名> <本地分支名>:<远程 ...
- hdu 1839 Delay Constrained Maximum Capacity Path
最短路+二分. 对容量进行二分,因为容量和时间是单调关系的,容量越多,能用的边越少,时间会不变或者增加. 因为直接暴力一个一个容量去算会TLE,所以采用二分. #include<cstdio&g ...
- MYSQL导入中文数据乱码的四种解决办法
方法一:通过增加参数 --default-character-set = utf8 解决乱码问题 方法一:通过增加参数 --default-character-set = utf8 解决乱码问题 my ...
- 苹果dock效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- netty初探(1)
参考目录: 1. user-guide : http://netty.io/wiki/user-guide-for-4.x.html 2. demo: http://netty.io/wiki/ 3. ...
- ElasticSearch(5)-Mapping
一.Mapping概述 映射 为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成全文本(Full-text)或精确的字符串值,Elasticsearch需要知道每个字段里面都包含了 ...
- hdu 5876 Sparse Graph icpc大连站网络赛 1009 补图最短路
BFS+链表 代码改自某博客 #include<stdio.h> #include<iostream> #include<algorithm> #include&l ...
- NOIP2013-普及组复赛-第一题-计数问题
题目描述 Description 试计算在区间 1 到 n 的所有整数中,数字 x(0 ≤ x ≤ 9)共出现了多少次?例如,在 1到 11 中,即在 1.2.3.4.5.6.7.8.9.10.11 ...