標籤

bat (54) 作品 (41) python (24) shell (17) windows (11) 虛擬機 (11) php (10) CPP (6) KMS (6) 程式設計 (6) docker (5) 使用教學 (5) xoops (4) 公文 (4) Apache2 (3) Excel (3) juniper (3) 資料庫 (3) 轉檔 (3) mysql (2) 免動手 (2) 資料結構 (2) 軟體廣播 (2) 電腦維修 (2) Android Studio (1) Apple IPAD管理 (1) Arduino (1) CSS (1) LAMP (1) NAS (1) Ubuntu (1) VHD (1) Windows Server (1) 原因 (1) 程式應用 (1) 程式積木 (1) 編輯器 (1) 雲端硬碟 (1)

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()


資料來源:

只要點兩下,就能夠將InputAndOutput資料夾底下的子子孫孫資料夾內所有Word通通轉成PDF

  系列文章: 1. 只要點兩下,就能將一堆的Doc與Docx 轉成 PDF 1. https://skjhcreator.blogspot.com/2023/05/docdocx-pdf.html 2. 只要點兩下,就能將一堆的JPG轉成一個PDF,並以JPG所在的資料夾名稱為...