Office2Pdf Class

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

IDSTCD_0000000002
LanguagePython
Steps149
PurposeConvert office file to pdf file.
FunctionConvert excel book/sheet to pdf file.
Convert word to pdf file.
Convert powerpoint to pdf file.
EnvironmentAnaconda3(Python 3.9.7)
IDE : Visual Studio Code
pywin32
Windows10
Restrictionfree license
You can use source code copy as owner .
You can customize and distribute it freely.
Price7 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

NOtest caseresult
01excel book test
– Change quality.
OK
02excel book test
– Change ignoreprintareas.
 IgnorePrintAreas parameter is not valid.
03excel book test
– Set page from and to.
From and To parameters are not valid.
04excel worksheet test
– Change quality.
OK
05excel worksheet test
– Change ignoreprintareas.
IgnorePrintAreas parameter is not valid.
06excel worksheet test
– Set page from and to.
From and To parameters are not valid.
07word test
– Change optimization.
OK
08word test
– Change range.
OK
09word test
– Change export item.
OK
10powerpoint test
– Change FrameSlides.
OK
11powerpoint test
– Change PrintHiddenSlides.
OK
12powerpoint 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 password

Following 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

Copied title and URL