把Word转换成pdf程序
来源:互联网 发布:update sql 多项条件 编辑:程序博客网 时间:2024/05/02 00:15
using oWord = Microsoft.Office.Interop.Word;
private void WordConvert()
{
oWord.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
Type wordType= word.GetType();
//打开WORD文档
/*对应脚本中的
var word = new ActiveXObject("Word.Application");
var doc = word.Documents.Open(docfile);
*/
oWord.Documents docs = word.Documents;
Type docsType = docs.GetType();
object objDocName = @"c:\test.doc";
oWord.Document doc = (oWord.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {objDocName, true, true});
//打印输出到指定文件
//你可以使用 doc.PrintOut();方法,次方法调用中的参数设置较繁琐,建议使用 Type.InvokeMember 来调用时可以不用将PrintOut的参数设置全,只设置4个主要参数
Type docType = doc.GetType();
object printFileName = @"c:\test.ps";
docType.InvokeMember("PrintOut",System.Reflection.BindingFlags.InvokeMethod,null,doc,new object[]{false,false,oWord.WdPrintOutRange.wdPrintAllDocument,printFileName});
//new object[]{false,false,oWord.WdPrintOutRange.wdPrintAllDocument,printFileName}
//对应脚本中的word.PrintOut(false, false, 0, psfile);的参数
//退出WORD
//对应脚本中的word.Quit();
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,null, word, null);
object o1= "c:\\test.ps";
object o2= "c:\\test.pdf";
object o3= "";
//引用将PS转换成PDF的对象
//try catch之间对应的是脚本中的 PDF.FileToPDF(psfile,pdffile,""); //你可以使用 pdfConvert.FileToPDF("c:\\test.ps","c:\\test.pdf","");这样的转换方法,本人只是为了保持与WORD相同的调用方式
try
{
ACRODISTXLib.PdfDistillerClass pdf = new ACRODISTXLib.PdfDistillerClass();
Type pdfType = pdfConvert.GetType();
pdfType.InvokeMember("FileToPDF",System.Reflection.BindingFlags.InvokeMethod,null,pdf,new object[]{o1,o2,o3});
pdf = null;
}
catch{} //读者自己补写错误处理
//为防止本方法调用多次时发生错误,必须停止acrodist.exe进程
foreach(Process proc in System.Diagnostics.Process.GetProcesses())
{
int begpos;
int endpos;
string sProcName = proc.ToString();
begpos = sProcName.IndexOf("(")+1;
endpos = sProcName.IndexOf(")");
sProcName=sProcName.Substring(begpos,endpos-begpos);
if(sProcName.ToLower().CompareTo("acrodist")==0)
{
try
{
proc.Kill(); //停止进程
}
catch{} //读者自己补写错误处理
break;
}
}
}
- 把Word转换成pdf程序
- 怎样把pdf转换成word
- 怎样把pdf转换成word
- 怎么把pdf转换成word文字
- 怎么把pdf转换成word文档
- 怎么样把pdf转换成word文档
- 如何才能把word转换成pdf文件
- ABBYY怎么把pdf转换成word
- 怎么用PDF转换器把pdf转换成word
- 把pdf转换成word格式的转换方法
- 分享把word转换成pdf格式的转换方法
- 活用office工具把PDF文件转换成word文件
- 怎样快速在线把pdf转换成word
- 如何在线把pdf转换成word转换器
- 在线把pdf文件转换成word详细教程
- 怎么把pdf文档内容转换成word
- 有什么方法把word转换成pdf
- 怎么把PDF文档转换成Word格式的步骤
- 浏览器兼容Event事件
- Yaffs2根文件系统制作
- Oracle其他数据对象 – 同义词
- dojo 的Events
- 各种排序的实现
- 把Word转换成pdf程序
- 百度mp3批量下载器 v1.0.2.5 绿色不要注册
- java-正则表达式判断手机号
- suse 11 linux server 配置puppet问题
- 智能指针shared_ptr组件的使用
- CentOS下安装Flashplayer
- spring.net 框架分析(二)IApplicationContext
- 11g不能在创建具有重复列的函数索引了
- wcf rest 从Message里获取原生body