μλ νμΈμ.
μ€λλ§μ νμ΄μ¬ μμ©μ κΈμ μ°λ κ² κ°μ΅λλ€.
μ΄μ κΈνκ² κ΅μλμ μ§μνμ μ± μ μ€μΊλ μ 볡μ¬νμ΅λλ€.
μ무λλ μλ μμΈ λ§νΌ μ€μΊμ ν νμ΄μ§ ν νμ΄μ§ λ¨λ κ²μ΄ λ무 νλ€μ΄μ νμ΄μ¬μΌλ‘ κΌΌμ μ’ μ¬μ©νμ΅λλ€.
μ± κ°μ κ²½μ°λ μλ©΄μΌλ‘ λμκΈ° λλ¬Έμ μ€μΊμ λ¨λ κ²μ΄ κ΅μ₯ν μ΄λ ΅μ΅λλ€.
μ°μμΌλ‘ ν λ©΄λ§ μ€μΊ λ° μ μλ νλ¦°νΈμ λλ€.
20 - 81 page λΌλ©΄,
μ : 20, 22, 24, 26 ~ 76, 78, 80 Page
λ€ : 21, 23, 25, 27 ~ 77, 79, 81 Page
λ‘ μ€μΊμ λ¬ ν, μ μ₯λ pdfλ₯Ό κ°νμ΄μ§λ₯Ό κ΅μ°¨ν΄μ ν©μ³€μ΅λλ€.
from PyPDF2 import PdfFileReader, PdfFileWriter
import os
# FIle name
base_path = os.getcwd()
file_name_1 = 'μ.pdf'
file_name_2 = 'λ€.pdf'
save_name = 'κ΅μ°¨.pdf'
# Path
file_path_1 = os.path.join(base_path, file_name_1)
file_path_2 = os.path.join(base_path, file_name_2)
save_path = os.path.join(base_path, save_name)
print(file_path_1)
print(file_path_2)
print(save_path)
# PDF Read
pdf_read_1 = PdfFileReader(open(file_path_1, 'rb'))
pdf_read_2 = PdfFileReader(open(file_path_2, 'rb'))
# PDF Write
pdf_writer = PdfFileWriter()
# Get number page
number_pages_1 = pdf_read_1.getNumPages()
number_pages_2 = pdf_read_2.getNumPages()
print(number_pages_1)
print(number_pages_2)
if number_pages_1 >= number_pages_2:
stop_point = number_pages_2
else:
stop_point = number_pages_1
# set up
i = 0
while(1):
if stop_point == i:
break
pdf_writer.addPage(pdf_read_1.getPage(i))
pdf_writer.addPage(pdf_read_2.getPage(i))
i = i + 1
with open(save_path, 'wb') as f:
pdf_writer.write(f)
κΈνκ² μ½λλ₯Ό μ§°μ§λ§, λμμ μ ν©λλ€.
μΈλΆ λΌμ΄λΈλ¬λ¦¬λ₯Ό μ½κ² λΆλ¬μ¬ μ μκ³ , μ½λ λν κ΅μ₯ν κ°λ¨ν©λλ€.
μ 곡μ μΈ λΆλΆμ΄ μλ, λ Όλ¦¬μ μΈ μ°κ²°μ μν¬ μ μλ€λ©΄ λꡬλ ν μ μ κ·Όν μ μλ κ²μ΄ νμ΄μ¬μ κ°μ μ λλ€.
μ λ§λ‘ λͺ λ λ€λ©΄ νμ΄μ¬μ μμ μ²λΌ μ€λ¬΄μμ μ¬μ©νλ λͺ¨μ΅μ λ³Ό μ μμ κ² κ°μ΅λλ€.
python -m pip install PyPDF2 # μ€μΉ