コード例 #1
0
        public void ToPdf()
        {
            bool occupy = true;

            while (occupy)
            {
                try
                {
                    using (File.Open(m_FilePathPowerPoint, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
                    { }
                    occupy = false;//如果可以运行至此那么就是
                }
                catch (IOException e)
                {
                    e.ToString();
                    Thread.Sleep(100);
                }
            }
            PPT.Application  pptApp       = null;
            PPT.Presentation presentation = null;
            try
            {
                pptApp       = new PPT.Application();
                presentation = pptApp.Presentations.Open(m_FilePathPowerPoint,
                                                         Microsoft.Office.Core.MsoTriState.msoCTrue,
                                                         Microsoft.Office.Core.MsoTriState.msoFalse,
                                                         Microsoft.Office.Core.MsoTriState.msoFalse);
                string strPdf = m_FilePathPowerPoint.Substring(0, m_FilePathPowerPoint.LastIndexOf('.')) + ".pdf";
                if (presentation != null)
                {
                    presentation.ExportAsFixedFormat(strPdf, PPT.PpFixedFormatType.ppFixedFormatTypePDF,
                                                     PPT.PpFixedFormatIntent.ppFixedFormatIntentPrint,
                                                     CORE.MsoTriState.msoFalse, PPT.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst,
                                                     PPT.PpPrintOutputType.ppPrintOutputSlides, Microsoft.Office.Core.MsoTriState.msoFalse,
                                                     null, PPT.PpPrintRangeType.ppPrintAll, "",
                                                     false, false, false, true, true, System.Reflection.Missing.Value);
                }
                if (presentation != null)
                {
                    presentation.Close();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(presentation);
                }
                if (pptApp != null)
                {
                    pptApp.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pptApp);
                }
                PostHttpMsg pm = new PostHttpMsg();
                pm.DataPost = strPdf;
                pm.PostMsg();
            }
            catch (System.Exception e)
            {
                e.ToString();
            }
            finally
            {
                presentation = null;
                pptApp       = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
コード例 #2
0
ファイル: Word2Pdf.cs プロジェクト: u-stone/code-database
        public void ToPdf()
        {
            bool occupy = true;
            System.Collections.Generic.List<string> strAry = new List<string>();
            while (occupy)
            {
                try
                {
                    using (File.Open(m_FilePathWord, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
                    { }
                    occupy = false;//如果可以运行至此那么就是
                }
                catch (IOException e)
                {
                    strAry.Add(e.ToString());

                    Thread.Sleep(100);
                }
            }
            WORD.ApplicationClass wordApp = new WORD.ApplicationClass();

            WORD._Document wordDoc = null;
            object paramSourceDoc = m_FilePathWord;
            object paramMissing = Type.Missing;
            string strPdf = m_FilePathWord.Substring(0, m_FilePathWord.LastIndexOf('.'));
            string paramExportFilePath = strPdf;
            WORD.WdExportFormat paramexportFormat = WORD.WdExportFormat.wdExportFormatPDF;
            bool paramOpenAfterExport = false;
            WORD.WdExportOptimizeFor parameExportOptimizeFor = WORD.WdExportOptimizeFor.wdExportOptimizeForPrint;
            WORD.WdExportRange parameExportRange = 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;
            try
            {
                wordDoc = wordApp.Documents.Open(
                    ref paramSourceDoc, 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 (wordDoc != null)
                {
                    wordDoc.ExportAsFixedFormat(paramExportFilePath,
                        paramexportFormat, paramOpenAfterExport,
                        parameExportOptimizeFor, parameExportRange, paramStartPage,
                        paramEndPage, paramExportItem, paramIncludeDocProps,
                        paramKeepIRM, paramCreateBookMarks, paramDocStructureTags,
                        paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing);
                }
                if (wordDoc != null)
                {
                    wordDoc.Close(ref paramMissing, ref paramMissing, ref paramMissing);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc);
                }
                if (wordApp != null)
                {
                    wordApp.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
                }
                PostHttpMsg pm = new PostHttpMsg();
                pm.DataPost = strPdf + ".pdf";
                pm.PostMsg();
            }
            catch (System.Exception ex)
            {
                ex.ToString();
            }
            finally
            {
                wordDoc = null;
                wordApp = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
コード例 #3
0
        public void ToPdf()
        {
            bool occupy = true;

            System.Collections.Generic.List <string> strAry = new List <string>();
            while (occupy)
            {
                try
                {
                    using (File.Open(m_FilePathWord, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
                    { }
                    occupy = false;//如果可以运行至此那么就是
                }
                catch (IOException e)
                {
                    strAry.Add(e.ToString());

                    Thread.Sleep(100);
                }
            }
            WORD.ApplicationClass wordApp = new WORD.ApplicationClass();

            WORD._Document wordDoc             = null;
            object         paramSourceDoc      = m_FilePathWord;
            object         paramMissing        = Type.Missing;
            string         strPdf              = m_FilePathWord.Substring(0, m_FilePathWord.LastIndexOf('.'));
            string         paramExportFilePath = strPdf;

            WORD.WdExportFormat paramexportFormat = WORD.WdExportFormat.wdExportFormatPDF;
            bool paramOpenAfterExport             = false;

            WORD.WdExportOptimizeFor parameExportOptimizeFor = WORD.WdExportOptimizeFor.wdExportOptimizeForPrint;
            WORD.WdExportRange       parameExportRange       = 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;

            try
            {
                wordDoc = wordApp.Documents.Open(
                    ref paramSourceDoc, 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 (wordDoc != null)
                {
                    wordDoc.ExportAsFixedFormat(paramExportFilePath,
                                                paramexportFormat, paramOpenAfterExport,
                                                parameExportOptimizeFor, parameExportRange, paramStartPage,
                                                paramEndPage, paramExportItem, paramIncludeDocProps,
                                                paramKeepIRM, paramCreateBookMarks, paramDocStructureTags,
                                                paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing);
                }
                if (wordDoc != null)
                {
                    wordDoc.Close(ref paramMissing, ref paramMissing, ref paramMissing);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc);
                }
                if (wordApp != null)
                {
                    wordApp.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
                }
                PostHttpMsg pm = new PostHttpMsg();
                pm.DataPost = strPdf + ".pdf";
                pm.PostMsg();
            }
            catch (System.Exception ex)
            {
                ex.ToString();
            }
            finally
            {
                wordDoc = null;
                wordApp = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
コード例 #4
0
ファイル: Excel2Pdf.cs プロジェクト: u-stone/code-database
        public void ToPdf()
        {
            bool occupy = true;

            while (occupy)
            {
                try
                {
                    using (File.Open(m_FilePathExcel, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
                    { }
                    occupy = false;//如果可以运行至此那么就是
                }
                catch (IOException e)
                {
                    e.ToString();
                    Thread.Sleep(100);
                }
            }
            XLS.Application xlsApp       = new Microsoft.Office.Interop.Excel.Application();
            object          paramMissing = Type.Missing;
            string          strXls       = m_FilePathExcel.Substring(0, m_FilePathExcel.LastIndexOf('.')) + ".pdf";

            XLS.Workbook workbook = null;
            try
            {
                workbook = xlsApp.Workbooks.Open(m_FilePathExcel, paramMissing, paramMissing,
                                                 paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing,
                                                 paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing);
                if (workbook != null)
                {
                    workbook.ExportAsFixedFormat(XLS.XlFixedFormatType.xlTypePDF, strXls, paramMissing,
                                                 paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing);
                }
                if (workbook != null)
                {
                    workbook.Close(Type.Missing, Type.Missing, Type.Missing);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
                }
                xlsApp.Workbooks.Close();
                if (xlsApp != null)
                {
                    xlsApp.Workbooks.Close();
                    xlsApp.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsApp);
                }
                PostHttpMsg pm = new PostHttpMsg();
                pm.DataPost = strXls;
                pm.PostMsg();
            }
            catch (System.Exception e)
            {
                e.ToString();
            }
            finally
            {
                workbook = null;
                xlsApp   = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
コード例 #5
0
ファイル: Excel2Pdf.cs プロジェクト: u-stone/code-database
 public void ToPdf()
 {
     bool occupy = true;
     while (occupy)
     {
         try
         {
             using (File.Open(m_FilePathExcel, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
             { }
             occupy = false;//如果可以运行至此那么就是
         }
         catch (IOException e)
         {
             e.ToString();
             Thread.Sleep(100);
         }
     }
     XLS.Application xlsApp = new Microsoft.Office.Interop.Excel.Application();
     object paramMissing = Type.Missing;
     string strXls = m_FilePathExcel.Substring(0, m_FilePathExcel.LastIndexOf('.')) + ".pdf";
     XLS.Workbook workbook = null;
     try
     {
         workbook = xlsApp.Workbooks.Open(m_FilePathExcel, paramMissing, paramMissing,
             paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing,
             paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing);
         if (workbook != null)
         {
             workbook.ExportAsFixedFormat(XLS.XlFixedFormatType.xlTypePDF, strXls, paramMissing,
                 paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing);
         }
         if (workbook != null)
         {
             workbook.Close(Type.Missing, Type.Missing, Type.Missing);
             System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
         }
         xlsApp.Workbooks.Close();
         if (xlsApp != null)
         {
             xlsApp.Workbooks.Close();
             xlsApp.Quit();
             System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsApp);
         }
         PostHttpMsg pm = new PostHttpMsg();
         pm.DataPost = strXls;
         pm.PostMsg();
     }
     catch (System.Exception e)
     {
         e.ToString();
     }
     finally
     {
         workbook = null;
         xlsApp = null;
         GC.Collect();
         GC.WaitForPendingFinalizers();
         GC.Collect();
         GC.WaitForPendingFinalizers();
     }
 }
コード例 #6
0
 public void ToPdf()
 {
     bool occupy = true;
     while (occupy)
     {
         try
         {
             using (File.Open(m_FilePathPowerPoint, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
             { }
             occupy = false;//如果可以运行至此那么就是
         }
         catch (IOException e)
         {
             e.ToString();
             Thread.Sleep(100);
         }
     }
     PPT.Application pptApp = null;
     PPT.Presentation presentation = null;
     try
     {
         pptApp = new PPT.Application();
         presentation = pptApp.Presentations.Open(m_FilePathPowerPoint,
             Microsoft.Office.Core.MsoTriState.msoCTrue,
             Microsoft.Office.Core.MsoTriState.msoFalse,
             Microsoft.Office.Core.MsoTriState.msoFalse);
         string strPdf = m_FilePathPowerPoint.Substring(0, m_FilePathPowerPoint.LastIndexOf('.')) + ".pdf";
         if (presentation != null)
         {
             presentation.ExportAsFixedFormat(strPdf, PPT.PpFixedFormatType.ppFixedFormatTypePDF,
                 PPT.PpFixedFormatIntent.ppFixedFormatIntentPrint,
                 CORE.MsoTriState.msoFalse, PPT.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst,
                 PPT.PpPrintOutputType.ppPrintOutputSlides, Microsoft.Office.Core.MsoTriState.msoFalse,
                 null, PPT.PpPrintRangeType.ppPrintAll, "",
                 false, false, false, true, true, System.Reflection.Missing.Value);
         }
         if (presentation != null)
         {
             presentation.Close();
             System.Runtime.InteropServices.Marshal.ReleaseComObject(presentation);
         }
         if (pptApp != null)
         {
             pptApp.Quit();
             System.Runtime.InteropServices.Marshal.ReleaseComObject(pptApp);
         }
         PostHttpMsg pm = new PostHttpMsg();
         pm.DataPost = strPdf;
         pm.PostMsg();
     }
     catch (System.Exception e)
     {
         e.ToString();
     }
     finally
     {
         presentation = null;
         pptApp = null;
         GC.Collect();
         GC.WaitForPendingFinalizers();
         GC.Collect();
         GC.WaitForPendingFinalizers();
     }
 }