把文件(office文件、图片等文件)转换为pdf文件,各位有啥好的建议?
目前采取朋友的建议,C#调用虚拟打印机(项目中用BullZip Printer)来把文件转换为pdf文件,word转换pdf后,打开pdf文件报错:
Adobe Reader无法打开"XX.pdf",因为不支持此文件类型或者文件已损坏。
以下是源码,请教高人指点: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);        }

解决方案 »

  1.   

    你这种貌似就把后缀输出成了pdf
    http://www.hbjjrb.com/Jishu/ASPNET/200704/5929.html
    你看一下这里面有把word转为pdf的方法主要用到PDF Distiller看看是否满足你的需求
      

  2.   

    换别的虚拟打印机,PDF Creator或者官方的虚拟打印机
      

  3.   

    换个.pdf文件试
    http://topic.csdn.net/u/20100415/17/687b3da9-436a-4560-97fa-72e53bbcf6e0.html
      

  4.   

    已通过调用Bullzip printer实现word excel txt转换为pdf,还差image ppt等转换为pdf,到时候完成了拿出来同大家共享
      

  5.   

    不解,迷惑中:...等待楼主解决!!..string progid = "Bullzip.PDFPrinterSettings";
    中的Bullzip.PDFPrinterSettings是什么意思啊??
    我通过楼主的方法,执行到
    System.Type oType = System.Type.GetTypeFromProgID(progid);
    这句时,oType等于null
    我该怎么解决啊??Bullzip.PDFPrinterSettings是虚拟打印机的标识符id吗?
    如果是,我该怎么找?
      

  6.   

        public class WordCommonConsts
        {
            public static object docUnknowOption = System.Reflection.Missing.Value;
            
            public static object docTrue = true;
                    
            public static object docFalse = false;    }...wdoc对象是office com对象我用的Microsft Word 11.0.ObjectLibrary,是office2003的
    又引用了com组件的Bullzip,可以直接new,不用取type再生成对象            Bullzip.PDFPrinterSettingsClass pdfpset = new Bullzip.PDFPrinterSettingsClass();            string PrinterName = pdfpset.GetPrinterName();
                wdoc.WordDocObj.Application.ActivePrinter = PrinterName;                object copies = "1";
                    //object pages = "";
                    object range = Word.WdPrintOutRange.wdPrintAllDocument;
                    object items = Word.WdPrintOutItem.wdPrintDocumentContent;
                    object pageType = Word.WdPrintOutPages.wdPrintAllPages;                wdoc.PrintOut(ref WordCommonConsts.docFalse, ref WordCommonConsts.docFalse,ref range,ref WordCommonConsts.docUnknowOption,
                      ref WordCommonConsts.docUnknowOption, ref WordCommonConsts.docUnknowOption, ref items, ref copies,ref WordCommonConsts.docUnknowOption,
                      ref pageType,ref WordCommonConsts.docUnknowOption,ref WordCommonConsts.docUnknowOption, ref WordCommonConsts.docUnknowOption,
                      ref WordCommonConsts.docUnknowOption,ref WordCommonConsts.docUnknowOption,ref WordCommonConsts.docUnknowOption, 
                      ref WordCommonConsts.docUnknowOption, ref WordCommonConsts.docUnknowOption);
      

  7.   


    帮楼主回答一下:
    因为这种方法是通过虚拟打印机来制作PDF文件的,所以你需要安装一个虚拟打印机。随便给出个下载地址:http://zjwt.9xz.net/soft/201009/BullzipPDFPrinter_7_1_0_1212.rar