Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to convert word to pdf in python Automation Office

Shulou Source: shulou.com Published: 2022-06-02 03:25:53 11月17日 Update

This article introduces how to convert word to pdf in python automation office. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

How to use the pypiwin32 library to solve one of our common requirements: converting word documents into pdf documents

This is mainly achieved by simulating the function of MS Word or WPS to save as or export to pdf, so you need to install MS Office or WPS software on your computer, and the result is the same as manual conversion:

Introduction of ExportAsFixedFormat method

Simple implementation:

Import os

Import win32com.client

# word document path

Docx_path = 'awesome.docx'

# Word.Application, using MS word;Kwps.Application, using WPS

App = win32com.client.DispatchEx ("Kwps.Application")

# do not display the interface

App.Visible = False

# Open documents in read-only mode

Doc = app.Documents.Open (os.path.abspath (docx_path), ReadOnly=1)

# Export to PDF document, named: output_pdf.pdf

# you can also use the save as function: SaveAs

Doc.ExportAsFixedFormat (os.path.abspath ('output_pdf.pdf'), 17)

# close documents and software

Doc.Close ()

App.Quit ()

Conversion effect

If you need to convert bulk word to pdf, you just need to traverse the file conversion.

About python automation office how to transfer word to pdf to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Documents office automation content effects more software help good consistent interests functions functions guys buddies common manual files articles methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MariaDB NVidia Docker MySQL