Skill

Process and Generate PDF Documents

A skill covering essential PDF operations - merge, split, extract, OCR, watermark, encrypt - via Python libraries and CLI tools.

Works with githubpandas

72
Spark score
out of 100
Updated last month
Version 13.1.0

Add to Favorites

Why it matters

Automate the extraction, manipulation, and creation of PDF documents using Python libraries and command-line tools. This asset provides a comprehensive guide for handling various PDF processing tasks.

Outcomes

What it gets done

01

Extract text and tables from PDFs

02

Merge, split, and rotate PDF pages

03

Create new PDFs from scratch

04

Perform OCR on scanned PDFs

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/ag-pdf-official | bash

Overview

PDF Processing Guide

Covers essential PDF operations - merge, split, extract text/tables, create, OCR, watermark, and encrypt - via pypdf, pdfplumber, reportlab, and CLI tools. Use for programmatic PDF manipulation; form-filling and advanced/JavaScript features are covered in separate reference docs, not here.

What it does

This skill covers essential PDF processing operations using Python libraries and command-line tools, functioning as a quick-reference guide for common document tasks. With pypdf it handles basic operations - reading and extracting text, merging multiple files, splitting a PDF into one file per page, reading metadata (title, author, subject, creator), and rotating pages:

from pypdf import PdfWriter, PdfReader

writer = PdfWriter()
for pdf_file in ["doc1.pdf", "doc2.pdf", "doc3.pdf"]:
    reader = PdfReader(pdf_file)
    for page in reader.pages:
        writer.add_page(page)

with open("merged.pdf", "wb") as output:
    writer.write(output)

With pdfplumber it extracts text with layout preserved and pulls tables out of pages, including converting extracted tables into pandas DataFrames and exporting them to Excel. With reportlab it builds new PDFs from scratch, either drawing directly onto a canvas or composing multi-page documents with Platypus (SimpleDocTemplate, Paragraph, PageBreak).

On the command line it uses pdftotext (from poppler-utils) for text extraction with optional layout preservation and page-range selection, qpdf for merging, splitting, rotating, and removing password protection, and pdftk as an alternative for merge/split/rotate. Additional common tasks covered include OCR on scanned PDFs (converting pages to images with pdf2image then running pytesseract, which requires installing both packages first), applying a watermark by merging a watermark page onto every page, extracting embedded images with pdfimages -j (writing sequentially numbered JPEG files), and adding password protection with pypdf's encrypt method, which accepts a separate user password and owner password.

When to use - and when NOT to

Use this skill when merging, splitting, extracting text or tables from, creating, watermarking, OCR'ing, or password-protecting PDF files programmatically. For filling out PDF forms specifically, the skill defers to a separate forms.md reference rather than covering it here; for advanced pypdfium2 usage, JavaScript libraries (pdf-lib), troubleshooting guides, and more detailed examples, it defers to reference.md.

Use this skill only when the task clearly matches the scope described above - it is not a substitute for environment-specific validation, testing, or expert review, and you should stop and ask for clarification if required inputs, permissions, or success criteria are missing.

Inputs and outputs

Inputs are PDF files (including scanned/image-based PDFs for OCR) and, for creation tasks, text content. Outputs are processed PDFs (merged, split, rotated, watermarked, encrypted), extracted text or tables, or newly generated PDF documents. A quick-reference table maps each task to its recommended tool: pypdf for merge/split, pdfplumber for text/table extraction, reportlab for creation, qpdf for command-line merging, and pytesseract for OCR.

Who it's for

Developers who need to programmatically manipulate PDF documents - merging, splitting, extracting content, generating reports, or running OCR - as part of a document processing pipeline or one-off script.

Source README

This guide covers essential PDF processing operations using Python libraries and command-line tools. 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.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.