標籤

bat (52) 作品 (38) python (21) 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) 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年6月21日 星期三

只要點兩下,就能將一堆的JPG轉成一個PDF,並以JPG所在的資料夾名稱為PDF的檔名

        Just two clicks and you can convert a bunch of JPGs into a single PDF, with the PDF file named after the folder where the JPGs are located. 

       現在遇到一個問題,這個問題是要將一堆的JPG轉成一個PDF,並且這個PDF的檔名為一堆JPG所在的資料夾名稱。
       I am currently facing an issue where I need to convert a bunch of JPGs into a single PDF, and the PDF file should be named after the folder where the JPGs are located.
 
       在資料來源1.Convert Images to PDF using Python,發現程式碼如下:
       In data source 1, "Convert Images to PDF using Python," I found the following code:
from PIL import Image

image_1 = Image.open(r'path where the image is stored\file name.png')
im_1 = image_1.convert('RGB')
im_1.save(r'path where the pdf will be stored\new file name.pdf')

所以我需要安裝套件 Pillow、jpg檔案位置。
So I need to install the Pillow package and provide the location of the JPG files. 
                     下載檔案解壓密碼:demo1234
Here is the website where you can download the program and find instructions:
Download。Extraction Password: demo1234
使用教學(Instructional videos):

以下是開發過程與原始碼 (Development process and code):
安裝Pillow套件(Install the Pillow suite)      
安裝套件指令(command):pip install Pillow
 
       程式名稱(Program name):jpg2pdf.py
       程式內容(Code):
from PIL import Image
import os

#取得當前目錄
Path = os.getcwd()
#取得input路徑
InputPath = Path+'\\input\\'
#取得input資料夾下的目錄或檔案
dirs = os.listdir(InputPath)
# 建立字典與串列
pdfname = dict()
pdfadds = []
jpglist = []
#逐一檢查input資料夾下的目錄或檔案
for dir in dirs:
    #print(dir)
    #目錄的處理
    if os.path.isdir(InputPath+'\\'+dir+'\\'):
        pdfadds = os.listdir(InputPath+'\\'+dir)
        pdfname[dir] = pdfadds
    #檔案的處理    
    elif os.path.isfile(InputPath+'\\'+dir):
        #檢查檔案副檔名為jpg
        if dir.split('.')[1] == 'jpg':
            jpglist.append(dir)
# 目錄-> jpglist        
pdfname['input'] = jpglist            

#jpg 轉 pdf
for key in pdfname.keys():
    TempIm_list = []
    Tempk = 0
    TempPdfName = str(key+'.pdf')
    for i in pdfname[key]:
        if key != 'input':
            # 處理放在資料夾內的jpg
            ImagePath = InputPath+'\\'+key+'\\'+i
        elif key == 'input':
            # 處理放在input 的jpg
            ImagePath = InputPath+'\\'+i
        Tempk = Tempk + 1
        if Tempk == 1:
            TempImage_1 = Image.open(ImagePath)
            TempIm_1 = TempImage_1.convert('RGB')
        else:
            TempImage = Image.open(ImagePath)
            TempIm= TempImage.convert('RGB')
            TempIm_list.append(TempIm)
    TempIm_1.save(TempPdfName,save_all=True,append_images=TempIm_list)

       
資料來源:
4.




只要點兩下,傳統右鍵選單改回Win11右鍵選單

系列文章: 1. 只要點兩下,就能將Win11 右鍵選單 回復 傳統右鍵選單 2. 只要點兩下,傳統右鍵選單改回Win11右鍵選單 上一篇提到只要點兩下,就能將Win11選單回到傳統選單。但是有沒有方法能夠回到Win11選單呢?                    ...