服务器端打开office然后采用虚拟打印 转换成pdf

 [WebMethod]
public bool ConvertWordTOPDF(string WordPath)
{
bool ret=false;
#region
//string dataName = collection[i].FileName;//本地文件名称(带路径)
//string ip=Request.UserHostAddress;
//string wordname=WordPath;
string wordPath=WordPath;
string pdfPath=wordPath.Split('.')[]+".pdf";
oWord._Document m_Document = null;
oWord._Application m_wordApplication = null;
object oMissing = Type.Missing;
oWord.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
try
{
object obj = System.Reflection.BindingFlags.InvokeMethod;
Type wordType = word.GetType();
oWord.Documents docs = word.Documents;
Type docsType = docs.GetType();
object objDocName = wordPath;
oWord.Document doc = (oWord.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { objDocName, true, true });
//打印输出到指定文件
Type docType = doc.GetType();
object printFileName =wordPath.Split('.')[]+".ps";
docType.InvokeMember("PrintOut", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { false, false, oWord.WdPrintOutRange.wdPrintAllDocument, printFileName });
object savechanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges;
object saveasPath =wordPath.Split('.')[]+"new.doc";
//必须另存为!
doc.SaveAs(ref saveasPath, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
//必须关闭
doc.Close(ref savechanges, ref oMissing, ref oMissing);
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null,word, null);
//删除另存为文件
try
{
System.IO.File.Delete(saveasPath.ToString());
}
catch
{
}
string o1 = printFileName.ToString();//与生产的PS文件同步
string o2 = pdfPath;
string o3 = "";
//引用将PS转换成PDF的对象
try
{
ACRODISTXLib.PdfDistillerClass pdf = new ACRODISTXLib.PdfDistillerClass();
Type pdfType = pdf.GetType();
pdfType.InvokeMember("FileToPDF", System.Reflection.BindingFlags.InvokeMethod, null, pdf, new object[] { o1, o2, o3 });
pdf = null;
//System.IO.File.Delete( "123.log");//清除转换日志文件
}
catch
{ //throw new Exception("PS转PDF处出错!");
}
System.IO.File.Delete( printFileName.ToString());//清除ps文件 System.IO.File.Delete( printFileName.ToString().Split('.')[]+".log");//清除转换日志文件 if(System.IO.File.Exists(pdfPath))
{
ret=true;
}
//为防止本方法调用多次时发生错误,必须停止acrodist.exe进程
foreach (Process proc in System.Diagnostics.Process.GetProcesses())
{
int begpos;
int endpos; string sProcName = proc.ToString();
begpos = sProcName.IndexOf("(") + ;
endpos = sProcName.IndexOf(")"); sProcName = sProcName.Substring(begpos, endpos - begpos); if (sProcName.ToLower().CompareTo("acrodist") == )
{
try
{
proc.Kill();
}
catch { }
break;
}
}
}
catch(Exception ex)
{ } return ret;
#endregion
}

服务器端打开office然后采用虚拟打印 转换成pdf的更多相关文章

  1. c# office转换成pdf

    下载地址 [url]http://www.microsoft.com/downloads/details.aspx?FamilyId=4D951911-3E7E-4AE6-B059-A2E79ED87 ...

  2. java调用com组件将office文件转换成pdf

    在非常多企业级应用中都涉及到将office图片转换成pdf进行保存或者公布的场景,由于pdf格式的文档方便进行加密和权限控制(类似于百度文库).总结起来眼下将office文件转换 成pdf的方法主要有 ...

  3. C#将Word转换成PDF方法总结(基于Office和WPS两种方案)

    有时候,我们需要在线上预览word文档,当然我们可以用NPOI抽出Word中的文字和表格,然后显示到网页上面,但是这样会丢失掉Word中原有的格式和图片.一个比较好的办法就是将word转换成pdf,然 ...

  4. C#实现文档转换成PDF

    网上有很多将doc.ppt.xls等类型的文档转换成pdf的方法,目前了解到的有两大类: 1.使用虚拟打印机将doc.ppt.xls等类型的文档 2.使用OFFICE COM组件 我采用了第二种方法实 ...

  5. ASP.NET将word文档转换成pdf的代码

    一.添加引用 using Microsoft.Office.Interop.Word; 二.转换方法 1.方法 C# 代码 /// <summary> /// 把Word文件转换成pdf文 ...

  6. word ppt excel文档转换成pdf

    1.把word文档转换成pdf (1).添加引用 using Microsoft.Office.Interop.Word; 添加引用 (2).转换方法 /// <summary> /// ...

  7. 多页Excel转换成PDF时如何保存为单独文件

    通过ABBYY PDF Transformer+图文识别软件,使用PDF-XChange打印机将多页Excel工作簿转换成PDF文档(相关文章请参考ABBYY PDF Transformer+从MS ...

  8. 将caj转换成pdf

    1.工具准备 电脑一台 CAJViewer 7.2 foxit pdf reader [主是要拥有一个pdf的虚拟打印机,你也可以安装其他的可以取的pdf虚拟打印机的软件.] 2.步骤 (1)用CAJ ...

  9. ABBYY如何把图片转换成pdf格式

    在制作工作文件的时候,有时候会遇到需要进行文件格式转换的情况,比较常见的文件格式转换就包含了Office与pdf格式之间的转换.但除此之外,图片与pdf格式也是可以进行转换的,那么图片要怎么操作,才能 ...

随机推荐

  1. iOS流布局UICollectionView使用FlowLayout进行更灵活布局

    一.引言 前面的博客介绍了UICollectionView的相关方法和其协议中的方法,但对布局的管理类UICollectionViewFlowLayout没有着重探讨,这篇博客介绍关于布局的相关设置和 ...

  2. vim 缩写abbreviation

    创建 :ab abbreviation pharse 取消 :unab abbreviation 缩写使用 insert模式下输入缩写,Enter键获得pharse.

  3. 关于禁止ViewPager预加载问题【转】

    转自:http://blog.csdn.net/qq_21898059/article/details/51453938#comments 我最近上班又遇到一个小难题了,就是如题所述:ViewPage ...

  4. JAVA跑马灯实现1

    <TextView        android:layout_width="wrap_content"        android:layout_height=" ...

  5. (转)兼容主流浏览器的CSS透明代码

    透明往往能产生不错的网页视觉效果下面是兼容主流浏览器的CSS透明代码.transparent_class { filter:alpha(opacity=50); -moz-opacity:0.5; - ...

  6. BFC与IFC

    在我们做的网页上通常最重要的其中一点就是美观度,bfc他是一个块级格式化上下文,它是一个独立的渲染区域,只有Block-level box参与, 它规定了内部的Block-level Box如何布局, ...

  7. 实用脚本 - - insertAfter 在现有元素后插入一个新元素

    function insertAfter(newElement,targetElement){ var parent = targetElement.parentNode; if(parent.las ...

  8. 委托、 Lambda表达式和事件——事件

    /* * 由SharpDevelop创建. * 用户: David Huang * 日期: 2015/7/31 * 时间: 14:21 */ using System; namespace 事件 { ...

  9. html input 文本框的一些操作(限制输入...)

    1.取消按钮按下时的虚线框 在input里添加属性值 hideFocus 或者 HideFocus=true 2.只读文本框内容 在input里添加属性值 readonly 3.防止退后清空的TEXT ...

  10. xcode中如何安装多个版本的模拟器

    在xcode里面,安装的时间默认自带的有模拟器,有时间为了调试需要使用个多个版本的模拟器 在xcode  -> preference  里面 选择download,这里你可下载你需要的模拟器