PDF Processing Guide
Overview
This guide covers essential PDF processing operations using bundled Python libraries and scripts. For editing an existing PDF, read editing.md. For advanced features, JavaScript libraries, and detailed examples, see reference.md. If you need to fill out a PDF form, read forms.md and follow its instructions.
Rules
- For editing scenarios (such as document translation or editing), prioritize modifying the original PDF copy.
- For tasks where layout and visuals matter (such as reading, creating, editing or translating reports, invoices, slides, figures, paperwork etc.) or for filling and validating interactive PDF forms: 1.Prefer visual review: render PDF pages to PNGs and inspect them. 2.After each meaningful update, re-render pages and verify alignment, spacing, and legibility.
- Prefer PyMuPDF for existing-PDF operations. Use pypdf only for canonical AcroForm handling, encryption/repair edge cases, or operations PyMuPDF cannot perform reliably; use pdfplumber only as a table/edge-case fallback.
- Use the bundled Python libraries and scripts for all default workflows. Do not invoke a system CLI when PyMuPDF, pypdf, pdfplumber, reportlab, or Pillow can perform the operation.
- When extracting text, check page count, empty pages, repeated-page hashes, replacement characters, and a visual sample. Do not assume a larger character count is more accurate.
- Install the locked Python dependencies with
python -m pip install -r requirements.txt. - If the user has no explicit file format requirements, keep the same file extension as the source file。If the user explicitly specifies an output format, follow it.
- Do not convert a PDF to Word or a Lark/Feishu document merely because the task involves substantial content editing, reformatting, removing images, changing layout, or producing editable intermediate content. The complexity of the edit does not change the default deliverable.
- Route to PDF-to-Word only when the user explicitly requests Word, DOCX, or a Word-editable deliverable, or provides an editable Word file as the document to modify. Generic references to a “document,” “report,” “file,” “proposal,” or “editable file” do not by themselves mean Word. When routed, follow