반응형

Python Pillow 라이브러리를 이용해 PDF 변환기를 만들어 보자.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
from tkinter import filedialog
from PIL import Image
 
filename = filedialog.askopenfilename(
    filetypes = (("이미지 파일""*.jpg *.png"), ("모든 파일""*.*")),
    initialdir = os.getcwd())
# tkinter.filedialog.askopenfilename(**options)
# tkinter.filedialog.askopenfilenames(**options)
# The above two functions create an Open dialog and return the selected
# filename(s) that correspond to existing file(s).
 
newname = filename[0:-4]
ext = ".pdf"
 
try:
    with Image.open(filename) as pf:
        pf.save(newname + ext)
        print(filename + "  ===>  " + newname + ext)
except:
    print("Error")
 

 

파이썬 코드를 작성하고 실행한다.

 

파일 선택 다이얼로그에서 원하는 이미지 파일을 선택한다.

 

변환에 문제가 없다면 결과 화면이 출력된다.

 

PDF 파일이 생성된다.

 

※ 참고

Tkinter Dialogs

 

반응형
Posted by J-sean
: