I created all three PDFs and checked them. The one oddity is that the bullet characters in terms.pdf come out as (cid:127) when extracted.
Files (in the working folder, built by scripts/make.py, checked by scripts/check.py):
invoice.pdfis 1 page. It has a title for "Northwind Sample Co" and three line items, and everything is marked as sample.terms.pdfis 1 page. It has the heading "Sample Terms" and three bullet terms.combined.pdfis 2 pages, with the invoice first and the terms second. That matches 1 + 1 pages.
Text extracted from combined.pdf
- Page 1 has the invoice title, the "fictional / made-up sample data" note, the table rows, and the "SAMPLE - not a real invoice." footer.
- Page 2 has "Sample Terms" and the three terms: payment due in 30 days, 1% monthly late fee, and goods remaining sample property until paid. Each one is marked "(sample term)".
Table extracted from page 1 (one table found):
| Item | Qty | Unit Price | Amount |
|---|---|---|---|
| Sample Widget | 10 | $5.00 | $50.00 |
| Sample Gadget | 2 | $25.00 | $50.00 |
| Sample Service Hour | 4 | $30.00 | $120.00 |
| Total | $220.00 |
Verification: The line items add up: 50 + 50 + 120 = 220, which matches the stated total. The extracted table has the same 5 rows and 4 columns I built, with no merged or missing cells.
Problem: pdfplumber reads the bullet glyph as (cid:127) instead of "•". That is how the built-in Helvetica font encodes the bullet, so it is probably an extraction quirk and the bullets should display normally. I haven't rendered the pages, so I can't confirm how they look. If clean extracted text matters to you, I can switch to a plain "-" marker.
Test run: two sample one-page PDFs built with reportlab, merged with pypdf, then read back with pdfplumber, in a temporary folder. The run was allowed to write files and run python3 only. I re-opened the files myself: 1 + 1 pages merged into 2, and the table text matched. The model flagged that the bullet glyph extracts as (cid:127). Pages were not rendered, so appearance was not checked. All content is sample.
Qué hace
Usa tres bibliotecas conocidas: pypdf para la estructura (unir, dividir, reordenar, rotar, formularios y metadatos), pdfplumber para texto y tablas, y reportlab para generar PDF nuevos. Primero inspecciona cada archivo de entrada (número de páginas, tamaños, cifrado, campos de formulario y cuánto texto tiene cada página, lo que muestra desde el principio si una página es un escaneo), después ejecuta la tarea y vuelve a abrir cada archivo de salida para comprobar el número de páginas, una muestra de texto, los valores de los formularios y el tamaño del archivo. Informa de las páginas sin texto extraíble e indica que necesitan OCR, y advierte de que las tablas extraídas pueden no ser fiables. Solo abre un PDF protegido con una contraseña que proporciones para un archivo que puedas usar, y no intenta romper la protección.
Salida
Los nuevos archivos PDF y el script que los creó, qué cambió, el resultado de la verificación y los problemas detectados, como páginas escaneadas o fuentes ausentes.
Ideal para
Unir y dividir documentos, extraer tablas de informes, estampar marcas de agua y números de página, rellenar formularios y generar facturas o informes sencillos.
Riesgo medio: solo instrucciones, no incluye scripts propios, pero escribe y ejecuta Python que crea archivos en tu carpeta de trabajo y puede sugerir instalar pypdf, pdfplumber y reportlab en un entorno virtual. Nunca sobrescribe tus originales ni rompe la protección con contraseña. Se probó una vez en una carpeta temporal con PDF de muestra: generó dos PDF, los unió y extrajo la tabla correctamente; el glifo de viñeta apareció como (cid:127) al extraerlo, y las páginas no se renderizaron, así que no se comprobó el aspecto. Original de AIBars (MIT).