2023年5月31日 星期三

只要點兩下,就能將一堆的Doc與Docx 轉成 PDF

 
Just two clicks and you can convert a bunch of Doc and Docx files into PDF format.
 
        最近遇到一個問題,想要把一堆的Word 轉成PDF。當然可以用手動的方式,一個個用Word打開,另存新檔,然後另存成PDF。可是這樣很麻煩,要是有100多個以上的Doc與Docx,然後要一一打開後再另存成PDF。有沒有更快的方法!!只要讓我點兩下滑鼠,不管有多少個Doc與Docx就能自動轉換成PDF?
 
        I recently encountered a problem where I wanted to convert a bunch of Word files into PDFs. Of course, I could do it manually by opening each file in Word, saving it as a new file, and then saving it as a PDF. But that's very tedious, especially if there are more than 100 Doc and Docx files that need to be converted. Is there a faster way? Ideally, I would like to be able to convert all of the files to PDF with just two clicks of the mouse, regardless of how many Doc and Docx files there are.
                     下載檔案解壓密碼:demo1234
Here is the website where you can download the program and find instructions:
Download。Extraction Password: demo1234
使用教學(Instructional videos):

安裝pywin32套件(Install the pywin32 suite)
指令(command):pip install pywin32

程式名稱(Program name):Word2Pdf.py
程式內容(Code):
# pip install pywin32
import glob
import os
from win32com import client

path=os.getcwd()
os.chdir(path+'\\input\\')
word = client.Dispatch("Word.Application")

for i in glob.glob('*.doc'):
    print("Convert "+path+'\\input\\'+i+" to PDF!")
    doc = word.Documents.Open(path+'\\input\\'+i)
    doc.SaveAs("{}.pdf".format(path+'\\output\\'+i[:-4]),17)
    print("{}.pdf".format(path+'\\output\\'+i[:-4])+" OK!")
    doc.Close()
for i in glob.glob('*.docx'):
    print("Convert "+path+'\\input\\'+i+" to PDF!")
    docx = word.Documents.Open(path+'\\input\\'+i)
    docx.SaveAs("{}.pdf".format(path+'\\output\\'+i[:-5]),17)
    print("{}.pdf".format(path+'\\output\\'+i[:-5])+" OK!")
    docx.Close()

word.Quit()


資料來源:

沒有留言:

張貼留言

Laravel 12 Model 資料庫中的資料表,並提供與資料庫互動的介面

相關系列文章: 1. 在 windows 10 安裝 laravel 12 studentManagement環境與設定 2. laravel 12 route 路由 3. laravel 12 Blade Templates 網頁模版 4. laravel 12 Control...