{"id":101474,"plugin_id":"plugins_6af4333b6f008191806d76e5f43ec5f9","kind":"skill","collection_source":"plugin_package","comparison_source":null,"observed_at":"2026-11-17T12:11:35.690Z","digest":"a3c8b1174d8f13675aecf3267b5837688f9f7d54391a744ca954d9fe2607926c","against":null,"payload":{"description":"Read, extract from, create, fill, merge, split, and watermark PDF files with pdfplumber, pypdf, and ReportLab. Use whenever the user uploads a PDF to summarize, extract text or tables from, or fill in, or wants a PDF as output — a report, invoice, letter, certificate, or a combined or redacted copy of other PDFs.","included_files":[],"name":"pdf","skill_md_contents":"---\nname: pdf\ndescription: Read, extract from, create, fill, merge, split, and watermark PDF files with pdfplumber, pypdf, and ReportLab. Use whenever the user uploads a PDF to summarize, extract text or tables from, or fill in, or wants a PDF as output — a report, invoice, letter, certificate, or a combined or redacted copy of other PDFs.\nlicense: Apache-2.0\ncompatibility: Tines 3B\n---\n\n# PDFs\n\nWork with PDFs in Python through `execute`, adding the libraries you need to a `requirements.txt` in `files`: `pdfplumber==0.11.10` for extraction, `pypdf==6.20.1` for page and form operations, and `reportlab==5.0.1` for creating new PDFs. In a workflow step, add them to the step’s `requirements.txt` instead.\n\nUser uploads arrive under `/3b/uploads/<id>/<file>`, which every execution can read. Write output to a persistent volume, such as `volumes: [\"documents\"]` and `/storage/documents/report.pdf`, then call `showStorageFile` so the user can preview and download it. Never overwrite the user’s upload.\n\n## Reading\n\nFor a short PDF, call `readStorageFile` on it: it returns the PDF for you to view directly, including its layout, charts, and scanned pages. Use code when the document is long, when you need exact values, or when you need tables as data:\n\n```python\nimport pdfplumber\n\nwith pdfplumber.open(\"/3b/uploads/abc/invoice.pdf\") as pdf:\n    print(len(pdf.pages), pdf.metadata)\n    for number, page in enumerate(pdf.pages, start=1):\n        print(f\"--- Page {number}\")\n        print(page.extract_text() or \"[no text layer]\")\n        for table in page.extract_tables():\n            for row in table:\n                print(row)\n```\n\nA page with no text layer is a scan. OCR tools aren’t installed in the sandbox, so view those pages with `readStorageFile` instead. Use `page.crop((x0, top, x1, bottom))` to read one region, such as a header block or a single column of a multi-column layout.\n\n## Creating\n\nUse ReportLab’s Platypus layer. It flows paragraphs, tables, and images across pages, so you don’t position each line by hand.\n\n```python\nfrom reportlab.lib import colors\nfrom reportlab.lib.pagesizes import LETTER\nfrom reportlab.lib.styles import getSampleStyleSheet\nfrom reportlab.lib.units import inch\nfrom reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, Table, TableStyle\n\nstyles = getSampleStyleSheet()\n\ndef footer(canvas, doc):\n    canvas.setFont(\"Helvetica\", 9)\n    canvas.drawRightString(LETTER[0] - inch, 0.6 * inch, f\"Page {doc.page}\")\n\ndoc = SimpleDocTemplate(\"/storage/documents/report.pdf\", pagesize=LETTER, title=\"Incident report\",\n                        leftMargin=inch, rightMargin=inch, topMargin=inch, bottomMargin=inch)\ntable = Table([[\"System\", \"Impact\", \"Status\"], [\"Okta\", \"Login delays\", \"Resolved\"]],\n              colWidths=[2 * inch, 2.75 * inch, 1.75 * inch], repeatRows=1)\ntable.setStyle(TableStyle([\n    (\"BACKGROUND\", (0, 0), (-1, 0), colors.HexColor(\"#1F4E79\")),\n    (\"TEXTCOLOR\", (0, 0), (-1, 0), colors.white),\n    (\"FONTNAME\", (0, 0), (-1, 0), \"Helvetica-Bold\"),\n    (\"GRID\", (0, 0), (-1, -1), 0.5, colors.HexColor(\"#BFBFBF\")),\n    (\"ROWBACKGROUNDS\", (0, 1), (-1, -1), [colors.white, colors.HexColor(\"#F2F2F2\")]),\n]))\ndoc.build([\n    Paragraph(\"Incident report\", styles[\"Title\"]),\n    Paragraph(\"Login delays on <b>October 3</b> affected 4% of users for 22 minutes.\", styles[\"BodyText\"]),\n    Spacer(1, 12),\n    table,\n], onFirstPage=footer, onLaterPages=footer)\n```\n\n- `Paragraph` takes a small HTML-like markup (`<b>`, `<i>`, `<font>`, `<br/>`), so escape `&`, `<`, and `>` in user text with `xml.sax.saxutils.escape`.\n- ReportLab’s built-in fonts (Helvetica, Times, Courier) cover only Latin-1, so other characters render as black boxes. For other text, register a TrueType font. The sandbox includes Liberation fonts under `/usr/share/fonts/truetype/liberation/`, and they cover Latin, Greek, and Cyrillic: `pdfmetrics.registerFont(TTFont(\"Liberation\", \".../LiberationSans-Regular.ttf\"))`.\n- Use A4 instead of Letter (`from reportlab.lib.pagesizes import A4`) for users outside North America.\n- Add charts as images: render a PNG with matplotlib at 200 DPI or more and add it with `reportlab.platypus.Image(path, width=..., height=...)`, keeping the aspect ratio.\n- For a document the user wants to edit afterward, produce a DOCX with the `docx` skill instead.\n\n## Page operations and forms\n\n```python\nfrom pypdf import PdfReader, PdfWriter\n\nwriter = PdfWriter()\nfor path in (\"/3b/uploads/a/cover.pdf\", \"/3b/uploads/b/body.pdf\"):\n    writer.append(path)\nwriter.add_metadata({\"/Title\": \"Combined report\"})\nwriter.write(\"/storage/documents/combined.pdf\")\n```\n\n- **Split or extract pages:** `writer.append(reader, pages=(0, 3))` copies pages 1–3.\n- **Rotate:** `page.rotate(90)`.\n- **Watermark or stamp:** build a one-page PDF with ReportLab, then call `page.merge_page(stamp_page)` on each page.\n- **Fill a form:** list the fields with `reader.get_fields()`. Then call `writer = PdfWriter(clone_from=reader)` and `writer.update_page_form_field_values(writer.pages[0], {\"name\": \"Ada\"}, auto_regenerate=False)`, and set `writer.set_need_appearances_writer(True)` so viewers draw the new values.\n- **Password-protect:** `writer.encrypt(user_password)`. Open an encrypted input with `reader.decrypt(password)`.\n\nDrawing a black box over text doesn’t redact it, because the text stays in the file and remains selectable. For real redaction, rebuild the affected pages without the text, or explain the limitation to the user.\n\n## Check the result\n\nCall `readStorageFile` on the output to view it as the user will: check page breaks, table overflow, fonts, and that nothing is cut off at the margins. Fix any problems, then call `showStorageFile` and tell the user the page count and what the document contains.\n"},"changes":[],"summary":"First saved snapshot. No earlier version is available for comparison.","summary_kind":"deterministic","summary_metadata":{}}