日期:2014-05-18 浏览次数:21216 次
public void PrintWordToPDF(string fileName) { string progid = "Bullzip.PDFPrinterSettings"; System.Type oType = System.Type.GetTypeFromProgID(progid); object obj_printer_settings = System.Activator.CreateInstance(oType); //找出虚拟打印机 string PrinterName = (string)oType.InvokeMember("GetPrinterName", System.Reflection.BindingFlags.InvokeMethod, null, obj_printer_settings, null); Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass(); Type wordType = word.GetType(); //打开WORD文档 Microsoft.Office.Interop.Word.Documents docs = word.Documents; Type docsType = docs.GetType(); object objDocName = fileSavePath+"\\"+fileName; Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { objDocName, true, true }); doc.Application.ActivePrinter = PrinterName; Type docType = doc.GetType(); object printFileName = fileSavePath+"\\"+GetFileName(fileName)+ ".pdf"; //打印输出 docType.InvokeMember("PrintOut", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { false, false, Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument, printFileName }); //退出WORD wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null); }