티스토리 뷰

참조 추가 => COM 에서 다음 항목들을 추가한다.

 

이후 아래의 코드를 사용하면 끝.

다만, 보안 문제가 있는 형식은 예외를 발생시키는데 이를 강제로 열 수 있는 방법을 찾아야한다. 

 public static void WordToPDF(string docPath, string exportPath)
        {
            Microsoft.Office.Interop.Word.Document wordDocument;
            Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
            // 경로, 파일 변환 대화상자 표시 안 함, 읽기 전용으로 열기
            wordDocument = appWord.Documents.Open(docPath, true, true);
            wordDocument.ExportAsFixedFormat(exportPath, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
            wordDocument.Close(false);
            appWord.Quit();
        }


        public static void ExcelToPDF(string xlsPath, string exportPath)
        {
            Microsoft.Office.Interop.Excel.Application appExcel = new Microsoft.Office.Interop.Excel.Application();
            appExcel.Visible = false;
            Microsoft.Office.Interop.Excel.Workbook workbook;
            workbook = appExcel.Workbooks.Open(xlsPath, Type.Missing, true);
            workbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, exportPath, Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard, true, true, Type.Missing, Type.Missing, false, Type.Missing);
            workbook.Close(false);
            appExcel.Quit();
        }


        public static void PPTToPDF(string pptPath, string exportPath)
        {
            Microsoft.Office.Interop.PowerPoint.Application appPPT = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentation presentation = appPPT.Presentations.Open(pptPath, Microsoft.Office.Core.MsoTriState.msoTrue,
                                                                                          Microsoft.Office.Core.MsoTriState.msoTrue,
                                                                                          Microsoft.Office.Core.MsoTriState.msoFalse);

            presentation.ExportAsFixedFormat(exportPath, Microsoft.Office.Interop.PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF,
            Microsoft.Office.Interop.PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentPrint,
            Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Interop.PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst,
            Microsoft.Office.Interop.PowerPoint.PpPrintOutputType.ppPrintOutputSlides, Microsoft.Office.Core.MsoTriState.msoFalse, null,
            Microsoft.Office.Interop.PowerPoint.PpPrintRangeType.ppPrintAll, string.Empty, true, true, true, true, false, Type.Missing);

            presentation.Close();
            appPPT.Quit();
        }

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함