With just a double-click, you can convert a bunch of PDF files placed in
the "input" folder into their respective Word documents.
最近遇到了問題,希望能將一堆PDF轉成各自的WORD,然後再進行編輯。目前市面上有類似的網站,可以提供PDF轉WORD。偏偏有些機密的PDF就不適合放到那些網站進行轉檔,怕洩密。若要不洩密,仍要轉檔成WORD,則需要購買版權。剛好,Python 就有PDF轉成DOCX的套件。但是需要填入檔名,一個一個地轉。因此,希望能夠有一種程式,只要將一堆的PDF放進INPUT資料夾,接著點兩下,相對應的WORD就會出現。
Recently, I encountered a problem and I hope to be able to convert a bunch of PDF files into individual Word documents for editing. Currently, there are similar websites available in the market that offer PDF to Word conversion. However, some confidential PDF files are not suitable for uploading to those websites for conversion due to security concerns. If I want to convert them to Word without compromising security, I would need to purchase a license. Luckily, there is a Python package available for converting PDF to DOCX. However, it requires filling in the file name and converting them one by one. Therefore, I would like to have a program where I can simply place a bunch of PDF files in the input folder, double-click, and the corresponding Word documents will be generated.
下載檔案。解壓密碼:demo1234
Here is the website where you can download the program and find instructions:
Download。Extraction Password: demo1234使用教學(Instructional videos):
以下是開發過程與原始碼 (Development process and code):
安裝pdf2docx套件(Install the pdf2docx suite)
指令(command):pip install pdf2docx
程式名稱(Program name):PdfToWord.py
程式內容(Code):
#請安裝套件 pdf2docx
#指令 pip install pdf2docx
from pdf2docx import Converter
import os
#取得當前目錄
Path = os.getcwd()
#取得input路徑
InputPath = Path+'\\input\\'
#取得input資料夾下的目錄或檔案
dirs = os.listdir(InputPath)
if dirs != []:
for dir in dirs:
fileName,fileExt = dir.split('.')
if fileExt.lower() == 'pdf':
PdfCvWord = Converter(InputPath+dir)
PdfCvWord.convert(Path+'\\'+fileName+'.docx')
PdfCvWord.close()
else:
print('Input is empty!!')
資料來源: