Process PDF files - extract text, create PDFs, merge documents. Use when user asks to read PDF, create PDF, or work with PDF files.
git clone https://github.com/shareAI-lab/learn-claude-code.git--- name: pdf description: Process PDF files - extract text, create PDFs, merge documents. Use when user asks to read PDF, create PDF, or work with PDF files. --- # PDF Processing Skill You now have expertise in PDF manipulation. Follow these workflows: ## Reading PDFs **Option 1: Quick text extraction (preferred)** ```bash # Using pdftotext (poppler-utils) pdftotext input.pdf - # Output to stdout pdftotext input.pdf output.txt # Output to file # If pdftotext not available, try: python3 -c " import fitz # PyMuPDF doc = fitz.open('input.pdf') for page in doc: print(page.get_text()) " ``` **Option 2: Page-by-page with metadata** ```python import fitz # pip install pymupdf doc = fitz.open("input.pdf") print(f"Pages: {len(doc)}") print(f"Metadata: {doc.metadata}") for i, page in enumerate(doc): text = page.get_text() print(f"--- Page {i+1} ---") print(text) ``` ## Creating PDFs **Option 1: From Markdown (recommended)** ```bash # Using pandoc pandoc input.md -o output.pdf # With custom styling pandoc input.md -o output.pdf --pdf-engine=xelatex -V geometry:margin=1in ``` **Option 2: Programmatically** ```python from reportlab.lib.pagesizes import letter from reportlab.pdfgen import canvas c = canvas.Canvas("output.pdf", pagesize=letter) c.drawString(100, 750, "Hello, PDF!") c.save() ``` **Option 3: From HTML** ```bash # Using wkhtmltopdf wkhtmltopdf input.html output.pdf # Or with Python python3 -c " import pdfkit pdfkit.from_file('input.html', 'output.pdf') " ``` ## Merging PDFs ```python import fitz result = fitz.open() for pdf_path in ["file1.pdf", "file2.pdf", "file3.pdf"]: doc = fitz.open(pdf_path) result.insert_pdf(doc) result.save("merged.pdf") ``` ## Splitting PDFs ```python import fitz doc = fitz.open("input.pdf") for i in range(len(doc)): single = fitz.open() single.insert_pdf(doc, from_page=i, to_page=i) single.save(f"page_{i+1}.pdf") ``` ## Key Libraries | Task | Library | Install | |------|---------|---------| | Read/Write/Merge | PyMuPDF | `pip install pymupdf` | | Create from scratch | ReportLab | `pip install reportlab` | | HTML to PDF | pdfkit | `pip install pdfkit` + wkhtmltopdf | | Text extraction | pdftotext | `brew install poppler` / `apt install poppler-utils` | ## Best Practices 1. **Always check if tools are installed** before using them 2. **Handle encoding issues** - PDFs may contain various character encodings 3. **Large PDFs**: Process page by page to avoid memory issues 4. **OCR for scanned PDFs**: Use `pytesseract` if text extraction returns empty
[{"step":"Prepare your files: Ensure the PDF(s) you want to process are accessible. For extraction, have the file path ready. For merging, gather all files to combine. For creation, prepare the text or document source.","tip":"Use absolute file paths (e.g., `/Users/username/Documents/file.pdf`) for reliability. Avoid spaces in filenames to prevent issues with some tools."},{"step":"Specify the action: Clearly state whether you want to extract text, create a new PDF, merge files, or convert formats. Include any customization (e.g., summary length, output filename).","tip":"For merging, list files in the order you want them combined. For text extraction, mention if you need a full transcript or a summarized version."},{"step":"Run the processing: Paste the prompt into your AI tool (e.g., Claude or ChatGPT) and execute it. If the tool supports file uploads, attach the PDF(s) directly.","tip":"For large PDFs, extraction may take longer. Break the file into smaller chunks if needed."},{"step":"Review and refine: Check the output for accuracy. If the AI misinterpreted data (e.g., tables, images), request corrections or manual adjustments.","tip":"Use tools like Adobe Acrobat or PDFescape for manual edits if the AI output isn’t perfect."},{"step":"Save or share: Once satisfied, save the output to your desired location or share it with stakeholders. For merged files, verify the order and completeness.","tip":"Name files descriptively (e.g., `Merged_Report_Q1_2024.pdf`) to avoid confusion later."}]
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/shareAI-lab/learn-claude-code/tree/main/skills/pdfCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Process the PDF file at [FILE_PATH] to [ACTION: extract text, create a new PDF, merge with another file, or convert to another format]. For extraction, summarize the key points in [NUMBER] bullet points. For merging, combine [FILE_PATH_1] and [FILE_PATH_2] into a single PDF named [OUTPUT_FILENAME]. For creation, generate a PDF from the content provided in [TEXT_OR_DOC_PATH]. Ensure the output is optimized for [USE_CASE: readability, printing, or editing].
I’ve processed the PDF file at `/Users/johndoe/Documents/Annual_Report_2023.pdf` to extract and summarize its key points. Here’s the concise breakdown: - **Financial Highlights**: Revenue grew by 12% YoY to $2.4B, with net income increasing by 18% to $420M. The report highlights strong performance in the EMEA region (+15% growth) and a 5% decline in the Americas due to supply chain disruptions. - **Strategic Initiatives**: Launched three new product lines in Q3, including the AI-driven analytics tool "Nexus Pro," which accounted for 8% of total revenue. The company also invested $50M in R&D for sustainable packaging solutions. - **Challenges**: Supply chain bottlenecks reduced operational efficiency by 7%, and regulatory changes in the EU added $12M in compliance costs. The report notes these are temporary setbacks with mitigation plans already in place. - **Outlook**: FY2024 projections indicate a 9-11% revenue growth, driven by expansion in APAC markets and the upcoming launch of "Nexus Enterprise." The extracted text is now saved as a clean, searchable PDF at `/Users/johndoe/Documents/Annual_Report_2023_Extracted.pdf`, optimized for readability and editing.
skills-collection
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan