顯示具有 PDF 標籤的文章。 顯示所有文章
顯示具有 PDF 標籤的文章。 顯示所有文章

2026年4月28日 星期二

只要點兩下,就能將input資料夾內所有PDF進行容量壓縮-版本01

系列文章:
01.python 不管何時何地,只要點兩下,資料夾內的所有pdf都會合併成一個pdf
https://skjhcreator.blogspot.com/2022/06/pythonpdfpdf.html
02.python 只要點兩下,分別對各資料夾內的pdf合併,合併後的檔名要讓人知道來自哪個資料夾 
https://skjhcreator.blogspot.com/2022/06/python-pdf.html
03. 只要點兩下,就能將一堆的Doc與Docx 轉成 PDF
03.https://skjhcreator.blogspot.com/2023/05/docdocx-pdf.html
04.只要點兩下,就能將一堆的JPG轉成一個PDF,並以JPG所在的資料夾名稱為PDF的檔名
04.https://skjhcreator.blogspot.com/2023/06/jpgpdfjpgpdf.html
05.只要點兩下,就能將放進input的一堆PDF轉成各自的WORD
05.https://skjhcreator.blogspot.com/2023/10/inputpdfword.html
06.只要點兩下,就能將放進input的一堆PDF轉成在ouput資料夾內的各自的WORD 
06.https://skjhcreator.blogspot.com/2023/10/inputpdfouputword.html
07.只要點兩下,就能夠將InputAndOutput資料夾底下的子子孫孫資料夾內所有Word通通轉成PDF
07.https://skjhcreator.blogspot.com/2024/09/word-word-pdf.html
08.只要點兩下,就可以將資料夾input內的所有Word通通轉成一個PDF
08.https://skjhcreator.blogspot.com/2025/07/inputwordpdf.html
09.只要點兩下兩次,就能依照設定拆分指定PDF頁數並合併成設定好的一個PDF
09.https://skjhcreator.blogspot.com/2025/09/pdfpdf.html
10.只要點兩下,就能將input資料夾內所有PDF進行容量壓縮-版本01
10.https://skjhcreator.blogspot.com/2026/04/inputpdf.html

Just double-click to compress all PDFs in the input folder.

        最近要上傳一大堆的PDF,常常因為PDF內的照片未經壓縮,導致整體容量過大。上傳時又因容量過大,導致無法上傳。上傳網站要求多少容量內的PDF才能上傳。問題是PDF不是我做的,偏偏又要發回或通知原主,要做PDF壓縮,才能上傳。如此的一來一往,浪費很多時間。能不能有個程式,讓我點個兩下就能將這些PDF進行壓縮,而不用再跟原主溝通?

        Recently, I’ve had to upload a large number of PDFs, but they’re often too big because the images inside them haven’t been compressed. As a result, the files exceed the upload size limit and can’t be uploaded. The website requires PDFs to be under a certain size, but the problem is that I didn’t create these PDFs. I end up having to send them back or notify the original creator to compress them before I can upload them. This back-and-forth wastes a lot of time.

        Is there a program that would let me simply double-click and compress these PDFs myself, without needing to communicate with the original creator?

下載檔案解壓密碼:demo1234
Here is the website where you can download the program and find instructions:
Download。Extraction Password: demo1234
使用教學(Instructional videos):




方法:Python + Ghostscript
一、下載與安裝 Ghostscript
到 https://www.ghostscript.com/download/gsdnld.html 下載後,點兩下進行安裝

二、Python 程式碼
檔案:pyPdfCompress.py
檔案內容:import os
import subprocess
import shutil
import webbrowser
import sys
import argparse
import platform

INPUT_DIR = "input"
OUTPUT_DIR = "output"

quality_settings = {
    "screen": "/screen",
    "ebook": "/ebook",
    "printer": "/printer",
    "prepress": "/prepress"
}


def check_ghostscript():
    gs = shutil.which("gswin64c") or shutil.which("gs")

    if gs is None:
        print("[未安裝Ghostscript]")

        if platform.system() == "Windows":
            print("請下載 Windows 版本 (gswin64)")
        else:
            print("請下載對應系統版本")

        print("即將開啟下載頁面...")

        webbrowser.open("https://www.ghostscript.com/download/gsdnld.html")

        print("若已安裝,請確認 Ghostscript 已加入 PATH")

        sys.exit(1)

    return gs


def compress_pdf(gs_command, input_path, output_path, quality):
    cmd = [
        gs_command,
        "-sDEVICE=pdfwrite",
        "-dCompatibilityLevel=1.4",
        f"-dPDFSETTINGS={quality_settings.get(quality, '/ebook')}",
        "-dNOPAUSE",
        "-dQUIET",
        "-dBATCH",
        f"-sOutputFile={output_path}",
        input_path
    ]

    result = subprocess.run(cmd, capture_output=True, text=True)

    if result.returncode != 0:
        raise RuntimeError(result.stderr)


def process_file(gs_command, file, quality):
    input_path = os.path.join(INPUT_DIR, file)

    name, ext = os.path.splitext(file)
    output_path = os.path.join(OUTPUT_DIR, f"{name}_compressed{ext}")

    compress_pdf(gs_command, input_path, output_path, quality)

    original_size = os.path.getsize(input_path) / 1024
    compressed_size = os.path.getsize(output_path) / 1024

    print(f"✔ {file}")
    print(f"   原始: {original_size:.2f} KB")
    print(f"   壓縮: {compressed_size:.2f} KB")

    if compressed_size >= original_size:
        print(" 壓縮後反而變大,已刪除壓縮檔\n")
        os.remove(output_path)
        return

    reduction = original_size - compressed_size
    ratio = (1 - compressed_size / original_size) * 100

    print(f"   減少: {reduction:.2f} KB")
    print(f"   壓縮率: {ratio:.2f}%\n")


def main():
    parser = argparse.ArgumentParser(description="PDF 批次壓縮工具")
    parser.add_argument(
        "--quality",
        choices=quality_settings.keys(),
        default="ebook",
        help="壓縮品質 (預設: ebook)"
    )
    args = parser.parse_args()

    gs_command = check_ghostscript()

    if not os.path.exists(INPUT_DIR):
        os.makedirs(INPUT_DIR)
        print(f"📁 已建立資料夾: {INPUT_DIR},請放入 PDF 後重新執行")
        return

    if not os.path.exists(OUTPUT_DIR):
        os.makedirs(OUTPUT_DIR)

    files = [f for f in os.listdir(INPUT_DIR) if f.lower().endswith(".pdf")]

    if not files:
        print("📂 input 資料夾內沒有 PDF")
        return

    for file in files:
        try:
            process_file(gs_command, file, args.quality)
        except Exception as e:
            print(f"✖ 失敗: {file}")
            print(e)
            print()


if __name__ == "__main__":
    main()

2025年9月21日 星期日

只要點兩下兩次,就能依照設定拆分指定PDF頁數並合併成設定好的一個PDF

系列文章:
01.python 不管何時何地,只要點兩下,資料夾內的所有pdf都會合併成一個pdf
https://skjhcreator.blogspot.com/2022/06/pythonpdfpdf.html
02.python 只要點兩下,分別對各資料夾內的pdf合併,合併後的檔名要讓人知道來自哪個資料夾 
https://skjhcreator.blogspot.com/2022/06/python-pdf.html
03. 只要點兩下,就能將一堆的Doc與Docx 轉成 PDF
03.https://skjhcreator.blogspot.com/2023/05/docdocx-pdf.html
04.只要點兩下,就能將一堆的JPG轉成一個PDF,並以JPG所在的資料夾名稱為PDF的檔名
04.https://skjhcreator.blogspot.com/2023/06/jpgpdfjpgpdf.html
05.只要點兩下,就能將放進input的一堆PDF轉成各自的WORD
05.https://skjhcreator.blogspot.com/2023/10/inputpdfword.html
06.只要點兩下,就能將放進input的一堆PDF轉成在ouput資料夾內的各自的WORD 
06.https://skjhcreator.blogspot.com/2023/10/inputpdfouputword.html
07.只要點兩下,就能夠將InputAndOutput資料夾底下的子子孫孫資料夾內所有Word通通轉成PDF
07.https://skjhcreator.blogspot.com/2024/09/word-word-pdf.html
08.只要點兩下,就可以將資料夾input內的所有Word通通轉成一個PDF
08.https://skjhcreator.blogspot.com/2025/07/inputwordpdf.html
09.只要點兩下兩次,就能依照設定拆分指定PDF頁數並合併成設定好的一個PDF
09.https://skjhcreator.blogspot.com/2025/09/pdfpdf.html
10.只要點兩下,就能將input資料夾內所有PDF進行容量壓縮
10.https://skjhcreator.blogspot.com/2026/04/inputpdf.html

        最近遇到一個問題,想要對四個不同的PDF,分別擷取1~2頁、3~4頁、5~6頁、7~8頁,合併成一個總共8頁的PDF。那該怎麼寫程式來處理這件事呢?那如果是用線上拆分PDF網頁與線上合併PDF網頁,該怎麼做呢?則是需要將四個不同PDF分別上傳到拆分網頁後再一頁一頁的PDF下載下來,再將所需要頁數的PDF放在同一個資料夾,然後再上傳到合併網頁,最後下到自己的資料夾。不斷地上傳、下載。光是處理這些步驟,所花的時間根本就無法想像。能不能有個程式,會掃描input資料夾內檔案。匯出input資料夾內所有檔案名稱,我們只要設定起始頁面與最後頁面。再對程式點兩下,就會合併所有的頁面到一個PDF。換句話說,只要點兩下兩次,就能依照設定拆分指定PDF頁數並合併成設定好的一個PDF。

下載檔案解壓密碼:demo1234
Here is the website where you can download the program and find instructions:
Download。Extraction Password: demo1234
使用說明(Instructions for use):
    1.下載後,解壓縮。解壓縮的方式要保持原有的資料夾架構,如下:
    意即解壓縮後,會看到內有一個pyPDFDivide.exe與兩個資料夾分別是      
     input 與 source 。如下圖:
    2.將所需的PDF 放入資料夾input 內
    3.滑鼠對pyPDFDivide.exe點兩下,就會產出一個OutputFileName.txt
    4.在OutputFileName.txt,填寫所需的頁數起始範圍後,儲存。
    5.滑鼠對pyPDFDivide.exe點兩下,就會產出output.pdf
    6.該output.pdf即為所求。
使用教學(Instructional videos):



以下是開發過程與原始碼 (Development process and code):
安裝python套件 pikepdf
pip install pikepdf
程式名稱(Program name):pyPDFDivide.py
程式內容(Code):
import os
from pikepdf import Pdf

# 取得目前的工作目錄
current_directory = os.getcwd()
# 取得目前的工作目錄內input資料夾的路徑
current_directory_input = current_directory + "\\input\\"
# 取得工作目錄input資料夾內所有檔案名稱
current_directory_input_files = os.listdir(current_directory_input)

# 檢查 OutputFileName.txt 是否存在
if os.path.exists(current_directory + "\\OutputFileName.txt"):
    # 如果存在,則讀取檔案內容
    with open("OutputFileName.txt", "r", encoding="utf-8") as file:
        content = file.readlines()
else:
    # 如果不存在,則創建 OutputFileName.txt 並寫入內容
    with open("OutputFileName.txt", "w", encoding="utf-8") as file:
        for current_directory_input_file in current_directory_input_files:
            # 開啟每個 PDF 檔案
            pdf = Pdf.open(current_directory_input + current_directory_input_file)
            pages = pdf.pages  # 獲取 PDF 檔案的頁面數量
            # 寫入檔案名稱和頁面數量到 OutputFileName.txt
            file.write("FileName:" + str(current_directory_input_file) + "\nTotalPages:" + str(len(pages)) + "\n" + "StartPage:\nEndPage:\n")

num = 0  # 計數器
FileNameList = []  # 存放檔案名稱的列表
StartPageList = []  # 存放起始頁面的列表
EndPageList = []  # 存放結束頁面的列表

# 解析 OutputFileName.txt 的內容
for i in content:
    if num % 4 == 0:
        # 每四行的第一行是檔案名稱
        temp, tempfilename = i.split(':')
        FileNameList.append(tempfilename.replace("\n", ""))
    elif num % 4 == 2:
        # 每四行的第三行是起始頁面
        temp, tempstartpage = i.split(':')
        StartPageList.append(tempstartpage.replace("\n", ""))
    elif num % 4 == 3:
        # 每四行的第四行是結束頁面
        temp, tempendpage = i.split(':')
        EndPageList.append(tempendpage.replace("\n", ""))
    num = num + 1  # 增加計數器

# 將設定檔 OutputFileName.txt 的內容依序將指定 PDF 拆分合併到 output.pdf
output = Pdf.new()  # 創建一個新的 PDF 檔案
for i in range(len(FileNameList)):
    # 開啟每個指定的 PDF 檔案
    pdf = Pdf.open(current_directory_input + FileNameList[i])
    pages = pdf.pages  # 獲取 PDF 檔案的頁面
    a = int(StartPageList[i])  # 轉換起始頁面為整數
    b = int(EndPageList[i])  # 轉換結束頁面為整數
    # 從起始頁面到結束頁面將頁面添加到新的 PDF 檔案中
    for j in range(a, b + 1):
        output.pages.append(pages[j])
# 儲存合併後的 PDF 檔案
output.save("output.pdf")


2025年7月21日 星期一

只要點兩下,就可以將資料夾input內的所有Word通通轉成一個PDF

系列文章:
01.python 不管何時何地,只要點兩下,資料夾內的所有pdf都會合併成一個pdf
https://skjhcreator.blogspot.com/2022/06/pythonpdfpdf.html
02.python 只要點兩下,分別對各資料夾內的pdf合併,合併後的檔名要讓人知道來自哪個資料夾 
https://skjhcreator.blogspot.com/2022/06/python-pdf.html
03. 只要點兩下,就能將一堆的Doc與Docx 轉成 PDF
03.https://skjhcreator.blogspot.com/2023/05/docdocx-pdf.html
04.只要點兩下,就能將一堆的JPG轉成一個PDF,並以JPG所在的資料夾名稱為PDF的檔名
04.https://skjhcreator.blogspot.com/2023/06/jpgpdfjpgpdf.html
05.只要點兩下,就能將放進input的一堆PDF轉成各自的WORD
05.https://skjhcreator.blogspot.com/2023/10/inputpdfword.html
06.只要點兩下,就能將放進input的一堆PDF轉成在ouput資料夾內的各自的WORD 
06.https://skjhcreator.blogspot.com/2023/10/inputpdfouputword.html
07.只要點兩下,就能夠將InputAndOutput資料夾底下的子子孫孫資料夾內所有Word通通轉成PDF
07.https://skjhcreator.blogspot.com/2024/09/word-word-pdf.html
08.只要點兩下,就可以將資料夾input內的所有Word通通轉成一個PDF
08.https://skjhcreator.blogspot.com/2025/07/inputwordpdf.html
09.只要點兩下兩次,就能依照設定拆分指定PDF頁數並合併成設定好的一個PDF
09.https://skjhcreator.blogspot.com/2025/09/pdfpdf.html
10.只要點兩下,就能將input資料夾內所有PDF進行容量壓縮
10.https://skjhcreator.blogspot.com/2026/04/inputpdf.html

     最近在行政處室內聽聞,常常要將很多的Word轉成一個個相對應的PDF,再將一個個對應的PDF合併成一個PDF。而那個PDF就是要交給上級的檔案。特別是要送課程計畫時候,常常會忙到忘了到底是哪個Word轉到哪個PDF?合併後的PDF會不會少哪個PDF?聽到這些聲音,就開始思考能不能將這些步驟省略,直接將很多Word轉一個PDF?

        Recently, I heard in the administrative office that there is often a need to convert many Word documents into corresponding PDFs, and then merge those PDFs into a single PDF. This final PDF is required to be submitted to superiors. Especially when submitting course plans, it often gets so busy that one forgets which Word document corresponds to which PDF, and whether any PDFs are missing after merging. Hearing these concerns, I started to think about whether it is possible to skip these steps and directly convert multiple Word documents into a single PDF.

下載檔案解壓密碼:demo1234
Here is the website where you can download the program and find instructions:
Download。Extraction Password: demo1234
使用教學(Instructional videos):



以下是開發過程與原始碼 (Development process and code):
 
安裝套件pypiwin32 、 PyPDF2 
指令(command):
pip install pypiwin32
pip install PyPDF2
 
程式名稱(Program name):AllWord2OnePDF.py
程式內容(Code):

import glob
import os
from win32com import client
import time
from PyPDF2 import PdfFileMerger

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

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

word.Quit()
print("WORD轉PDF 完成!!")
# PDF合併
pdf_lst = list()
# 設定Input為目標路徑
os.chdir(path+'\\output')
target_path=str(os.path.abspath(os.getcwd()))
# 列出目標路徑內的pdf
for f in os.listdir(target_path):
    if f.endswith('.pdf'):
        pdf_lst.append(os.path.join(target_path,f))

# pdf 合併
file_merger = PdfFileMerger()
for pdf in pdf_lst:
    file_merger.append(pdf)

output_name =path+"\\"+"merge"+str(time.strftime("%H-%M-%S",time.localtime()))+".pdf"
file_merger.write(output_name)
print("PDF合併 完成!!")  

資料來源:

2024年9月30日 星期一

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

系列文章:
01.python 不管何時何地,只要點兩下,資料夾內的所有pdf都會合併成一個pdf
https://skjhcreator.blogspot.com/2022/06/pythonpdfpdf.html
02.python 只要點兩下,分別對各資料夾內的pdf合併,合併後的檔名要讓人知道來自哪個資料夾 
https://skjhcreator.blogspot.com/2022/06/python-pdf.html
03. 只要點兩下,就能將一堆的Doc與Docx 轉成 PDF
03.https://skjhcreator.blogspot.com/2023/05/docdocx-pdf.html
04.只要點兩下,就能將一堆的JPG轉成一個PDF,並以JPG所在的資料夾名稱為PDF的檔名
04.https://skjhcreator.blogspot.com/2023/06/jpgpdfjpgpdf.html
05.只要點兩下,就能將放進input的一堆PDF轉成各自的WORD
05.https://skjhcreator.blogspot.com/2023/10/inputpdfword.html
06.只要點兩下,就能將放進input的一堆PDF轉成在ouput資料夾內的各自的WORD 
06.https://skjhcreator.blogspot.com/2023/10/inputpdfouputword.html
07.只要點兩下,就能夠將InputAndOutput資料夾底下的子子孫孫資料夾內所有Word通通轉成PDF
07.https://skjhcreator.blogspot.com/2024/09/word-word-pdf.html
08.只要點兩下,就可以將資料夾input內的所有Word通通轉成一個PDF
08.https://skjhcreator.blogspot.com/2025/07/inputwordpdf.html
09.只要點兩下兩次,就能依照設定拆分指定PDF頁數並合併成設定好的一個PDF
09.https://skjhcreator.blogspot.com/2025/09/pdfpdf.html
10.只要點兩下,就能將input資料夾內所有PDF進行容量壓縮
10.https://skjhcreator.blogspot.com/2026/04/inputpdf.html

        由於系列文章1~4 都是在Input資料夾內討論 Word 與 Pdf 互轉。面臨到資料夾內有子子孫孫資料夾,子子孫孫資料夾內有Word。那要如何將所有子子孫孫資料夾內的所有Word找出,並將之轉換成PDF?換句話說,可不可以有個程式,能夠將整理好的資料夾內所有Word 通通轉成PDF,即便資料夾內有很多個子資料夾,子資料夾內又有子資料夾。不管在哪個資料夾內的Word 都要將其找出並轉成PDF,轉出的PDF就在相對應的Word旁。

Since articles 1 to 4 discuss the conversion between Word and PDF within the Input folder, we are faced with the situation where there are nested subfolders containing Word documents. How can we find all the Word documents in these nested subfolders and convert them into PDF? In other words, is it possible to have a program that can convert all the Word documents in the organized folder, regardless of how many subfolders there are, and even if those subfolders contain their own subfolders? We need to find all the Word documents no matter where they are located within the folder structure and convert them into PDFs, with the resulting PDFs saved next to their corresponding Word files.

         下載檔案解壓密碼:demo1234
Here is the website where you can download the program and find instructions:
Download。Extraction Password: demo1234
使用教學(Instructional videos):





2023年10月18日 星期三

只要點兩下,就能將放進input的一堆PDF轉成在ouput資料夾內的各自的WORD

系列文章:
01.python 不管何時何地,只要點兩下,資料夾內的所有pdf都會合併成一個pdf
https://skjhcreator.blogspot.com/2022/06/pythonpdfpdf.html
02.python 只要點兩下,分別對各資料夾內的pdf合併,合併後的檔名要讓人知道來自哪個資料夾 
https://skjhcreator.blogspot.com/2022/06/python-pdf.html
03. 只要點兩下,就能將一堆的Doc與Docx 轉成 PDF
03.https://skjhcreator.blogspot.com/2023/05/docdocx-pdf.html
04.只要點兩下,就能將一堆的JPG轉成一個PDF,並以JPG所在的資料夾名稱為PDF的檔名
04.https://skjhcreator.blogspot.com/2023/06/jpgpdfjpgpdf.html
05.只要點兩下,就能將放進input的一堆PDF轉成各自的WORD
05.https://skjhcreator.blogspot.com/2023/10/inputpdfword.html
06.只要點兩下,就能將放進input的一堆PDF轉成在ouput資料夾內的各自的WORD 
06.https://skjhcreator.blogspot.com/2023/10/inputpdfouputword.html
07.只要點兩下,就能夠將InputAndOutput資料夾底下的子子孫孫資料夾內所有Word通通轉成PDF
07.https://skjhcreator.blogspot.com/2024/09/word-word-pdf.html
08.只要點兩下,就可以將資料夾input內的所有Word通通轉成一個PDF
08.https://skjhcreator.blogspot.com/2025/07/inputwordpdf.html
09.只要點兩下兩次,就能依照設定拆分指定PDF頁數並合併成設定好的一個PDF
09.https://skjhcreator.blogspot.com/2025/09/pdfpdf.html
10.只要點兩下,就能將input資料夾內所有PDF進行容量壓縮
10.https://skjhcreator.blogspot.com/2026/04/inputpdf.html

        By simply double-clicking, you can convert a bunch of PDF files that are placed in the input folder into their respective Word documents, which will be located in the output folder.


        根據上篇只要點兩下,就能將放進input的一堆PDF轉成各自的WORD,發現產出的WORD會跟執行程式PDFTOWORD.exe混在一起。當轉換的檔案多了,恐怕要用人工去一一核對,造成不便。如果產出的產出的WORD會集中在一個output資料夾,只要移動output資料即可。
 
        According to the previous article, by simply double-clicking, you can convert a bunch of PDF files that are placed in the input folder into their respective Word documents. However, it was found that the generated Word documents are mixed with the execution program PDFTOWORD.exe. When there are multiple converted files, it might be inconvenient to manually check each one. To address this issue, if the generated Word documents are centralized in an output folder, you can simply move the output folder.

下載檔案解壓密碼: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):PdfToWord01.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 os.path.exists(Path+'\\output'):
    #印出output資料夾存在
    print(Path+'\\output'+' exists!')
else:
    #建立output資料夾
    os.makedirs(Path+'\\output')

if dirs != []:
    for dir in dirs:
        fileName,fileExt = dir.split('.')
        if fileExt.lower() == 'pdf':
            PdfCvWord = Converter(InputPath+dir)
            PdfCvWord.convert(Path+'\\output\\'+fileName+'.docx')
            PdfCvWord.close()
else:
    print('Input is empty!!')



2023年10月17日 星期二

只要點兩下,就能將放進input的一堆PDF轉成各自的WORD

系列文章:
01.python 不管何時何地,只要點兩下,資料夾內的所有pdf都會合併成一個pdf
https://skjhcreator.blogspot.com/2022/06/pythonpdfpdf.html
02.python 只要點兩下,分別對各資料夾內的pdf合併,合併後的檔名要讓人知道來自哪個資料夾 
https://skjhcreator.blogspot.com/2022/06/python-pdf.html
03. 只要點兩下,就能將一堆的Doc與Docx 轉成 PDF
03.https://skjhcreator.blogspot.com/2023/05/docdocx-pdf.html
04.只要點兩下,就能將一堆的JPG轉成一個PDF,並以JPG所在的資料夾名稱為PDF的檔名
04.https://skjhcreator.blogspot.com/2023/06/jpgpdfjpgpdf.html
05.只要點兩下,就能將放進input的一堆PDF轉成各自的WORD
05.https://skjhcreator.blogspot.com/2023/10/inputpdfword.html
06.只要點兩下,就能將放進input的一堆PDF轉成在ouput資料夾內的各自的WORD 
06.https://skjhcreator.blogspot.com/2023/10/inputpdfouputword.html
07.只要點兩下,就能夠將InputAndOutput資料夾底下的子子孫孫資料夾內所有Word通通轉成PDF
07.https://skjhcreator.blogspot.com/2024/09/word-word-pdf.html
08.只要點兩下,就可以將資料夾input內的所有Word通通轉成一個PDF
08.https://skjhcreator.blogspot.com/2025/07/inputwordpdf.html
09.只要點兩下兩次,就能依照設定拆分指定PDF頁數並合併成設定好的一個PDF
09.https://skjhcreator.blogspot.com/2025/09/pdfpdf.html
10.只要點兩下,就能將input資料夾內所有PDF進行容量壓縮
10.https://skjhcreator.blogspot.com/2026/04/inputpdf.html

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!!')

 
 
資料來源:


只要點兩下,就能將input資料夾內所有m4a 轉檔為 mp3

         最近需要將m4a檔案轉檔為mp3,所以寫python程式來處理。希望將很多的m4a放進input資料夾內,只要點兩下滑鼠就能將這些m4a 通通轉檔為 mp3。          Recently, I needed to convert M4A files in...