For programmers to need to convert MS office file to PDF file by python,this tested source code is useful.
It is available to convert EXCEL book/sheet and WORD,PowerPoint to PDF.
Specification
| ID | STCD_0000000002 |
| Language | Python |
| Steps | 149 |
| Purpose | Convert office file to pdf file. |
| Function | Convert excel book/sheet to pdf file. Convert word to pdf file. Convert powerpoint to pdf file. |
| Environment | Anaconda3(Python 3.9.7) IDE : Visual Studio Code pywin32 Windows10 |
| Restriction | free license You can use source code copy as owner . You can customize and distribute it freely. |
| Price | 7 dollars or 700 yen (Pay with PayPal) |
| References | – About win32com client. https://learn.microsoft.com/en-us/office/vba/api/excel.workbook.exportasfixedformat https://learn.microsoft.com/en-us/office/vba/api/word.document.exportasfixedformat https://learn.microsoft.com/en-us/office/vba/api/powerpoint.presentation.exportasfixedformat – Etc https://sourceforge.net/p/pywin32/bugs/339/ https://learn.microsoft.com/ja-jp/office/vba/api/powerpoint.presentation.exportasfixedformat https://stackoverflow.com/questions/48257308/python-win32com-attribute-error-in-constants |
Source Code






Test Result
| NO | test case | result |
| 01 | excel book test – Change quality. | OK |
| 02 | excel book test – Change ignoreprintareas. | IgnorePrintAreas parameter is not valid. |
| 03 | excel book test – Set page from and to. | From and To parameters are not valid. |
| 04 | excel worksheet test – Change quality. | OK |
| 05 | excel worksheet test – Change ignoreprintareas. | IgnorePrintAreas parameter is not valid. |
| 06 | excel worksheet test – Set page from and to. | From and To parameters are not valid. |
| 07 | word test – Change optimization. | OK |
| 08 | word test – Change range. | OK |
| 09 | word test – Change export item. | OK |
| 10 | powerpoint test – Change FrameSlides. | OK |
| 11 | powerpoint test – Change PrintHiddenSlides. | OK |
| 12 | powerpoint test – Change RangeType. | OK (Can not set PpPrintRangeType.ppPrintNamedSlideShow and PpPrintRangeType.ppPrintSelection.) |
Test Code
*) Modify “path” along your PC environment.












History
17/11/2022 created
Provider Profile
Nick name is “Dead Fish” employed as an engineer in Japan.
I am grad if you need my code.
Thanks !
Download
Get download passwordFollowing files and data are zipped.
│ Office2PdfClass.py
│
├─test_excel
│ test.xlsx
│ test_fromto.pdf
│ test_ignoreprintarea_false.pdf
│ test_ignoreprintarea_true.pdf
│ test_quality_low.pdf
│ test_quality_normal.pdf
│ test_sheet_fromto.pdf
│ test_sheet_ignoreprintarea_false.pdf
│ test_sheet_ignoreprintarea_true.pdf
│ test_sheet_quality_low.pdf
│ test_sheet_quality_normal.pdf
│
├─test_ppt
│ test.pptx
│ test_FrameSlides_false.pdf
│ test_FrameSlides_true.pdf
│ test_PpPrintHandoutOrder_ppPrintHandoutHorizontalFirst.pdf
│ test_PpPrintHandoutOrder_ppPrintHandoutVerticalFirst.pdf
│ test_PrintHiddenSlides_msofalse.pdf
│ test_PrintHiddenSlides_msoTrue.pdf
│ test_RangeType_ppPrintAll.pdf
│ test_RangeType_ppPrintCurrent.pdf
│ test_RangeType_ppPrintSlideRange.pdf
│
└─test_word
test.docx
test_exportitem_wdExportDocumentContent.pdf
test_exportitem_wdExportDocumentWithMarkup.pdf
test_range_wdExportAllDocument.pdf
test_range_wdExportCurrentPage.pdf
test_range_wdExportFromTo.pdf
test_range_wdExportSelection.pdf
test_wdExportOptimizeForOnScreen.pdf
test_wdExportOptimizeForPrint.pdf
Remarks
None


Comments