Skip to content

Instantly share code, notes, and snippets.

@godie
Created June 4, 2024 16:25
Show Gist options
  • Save godie/fb708f26500bf43b5e1a8d26e396689c to your computer and use it in GitHub Desktop.
Save godie/fb708f26500bf43b5e1a8d26e396689c to your computer and use it in GitHub Desktop.
como unir pdfs con python
import PyPDF2
# Crear un objeto PDF en blanco
pdf_merger = PyPDF2.PdfFileMerger()
# Obtener la lista de archivos PDF a unir
pdf_files = ['archivo1.pdf', 'archivo2.pdf', 'archivo3.pdf']
# Iterar sobre los archivos PDF y agregarlos al objeto de combinación
for pdf_file in pdf_files:
with open(pdf_file, 'rb') as file:
pdf_reader = PyPDF2.PdfReader(file)
pdf_merger.append(pdf_reader)
# Escribir el archivo PDF combinado
output_file = 'archivo_combinado.pdf'
with open(output_file, 'wb') as file:
pdf_merger.write(file)
@godie
Copy link
Author

godie commented Jun 4, 2024

si marca error tenes que instalar el PyPDF2

pip install PyPDF2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment