Skip to main content

document-processing

Create, edit, and analyze office documents (PDF, DOCX, PPTX, XLSX). Use when working with PDFs, Word documents, PowerPoint presentations, or Excel spreadsheets. Covers text extraction, form filling, document creation, and data analysis.

来源信息

仓库
dirnbauer/webconsulting-skills
最近来源活动
2026年4月13日 22:21
检测到的 SKILL.md 语言
英语
星标
33
Forks
6

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
document-processing
description
Create, edit, and analyze office documents (PDF, DOCX, PPTX, XLSX). Use when working with PDFs, Word documents, PowerPoint presentations, or Excel spreadsheets. Covers text extraction, form filling, document creation, and data analysis.
license
Source-available (see github.com/anthropics/skills)
metadata
{"version":"1.0.0"}
# Document Processing > **Source:** This skill is adapted from **[Anthropic's document-processing skill](https://github.com/anthropics/skills/tree/main/skills/document-processing)** > document processing skills (pdf, docx, pptx, xlsx) for Claude Code and AI agents. Create, edit, and analyze office documents including PDFs, Word documents, PowerPoint presentations, and Excel spreadsheets. --- ## Quick Reference: Which Tool to Use | Task | Document Type | Best Tool | |------|---------------|-----------| | Extract text | PDF | `pdfplumber`, `pdftotext` | | Merge/split | PDF | `pypdf`, `qpdf` | | Fill forms | PDF | `pdf-lib` (JS), `pypdf` | | Create new | PDF | `reportlab` | | OCR scanned | PDF | `pytesseract` + `pdf2image` | | Extract text | DOCX | `pandoc`, `markitdown` | | Create new | DOCX | `docx-js` (JS) | | Edit existing | DOCX | OOXML (unpack/edit/pack) | | Extract text | PPTX | `markitdown` | | Create new | PPTX | `html2pptx`, `PptxGenJS` | | Edit existing | PPTX | OOXML (unpack/edit/pack) | | Data analysis | XLSX | `pandas` | | Formulas/formatting | XLSX | `openpyxl` | --- ## PDF Processing ### Text Extraction ```python import pdfplumber # Extract text with layout preservation with pdfplumber.open("document.pdf") as pdf: for page in pdf.pages: text = page.extract_text() print(text) ``` ### Table Extraction ```python import pdfplumber import pandas as pd with pdfplumber.open("document.pdf") as pdf: all_tables = [] for page in pdf.pages: tables = page.extract_tables() for table in tables: if table: df = pd.DataFrame(table[1:], columns=table[0]) all_tables.append(df) # Combine all tables if all_tables: combined_df = pd.concat(all_tables, ignore_index=True) combined_df.to_excel("extracted_tables.xlsx", index=False) ``` ### Merge PDFs ```python 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) ``` ### Split PDF ```python from pypdf import PdfReader, PdfWriter reader = PdfReader("input.pdf") for i, page in enumerate(reader.pages): writer = PdfWriter() writer.add_page(page) with open(f"page_{i+1}.pdf", "wb") as output: writer.write(output) ``` ### Rotate Pages ```python from pypdf import PdfReader, PdfWriter reader = PdfReader("input.pdf") writer = PdfWriter() page = reader.pages[0] page.rotate(90) # Rotate 90 degrees clockwise writer.add_page(page) with open("rotated.pdf", "wb") as output: writer.write(output) ``` ### OCR Scanned PDFs ```python # Requires: pip install pytesseract pdf2image import pytesseract from pdf2image import convert_from_path # Convert PDF to images images = convert_from_path('scanned.pdf') # OCR each page text = "" for i, image in enumerate(images): text += f"Page {i+1}:\n" text += pytesseract.image_to_string(image) text += "\n\n" print(text) ``` ### Add Watermark ```python from pypdf import PdfReader, PdfWriter watermark = PdfReader("watermark.pdf").pages[0] reader = PdfReader("document.pdf") writer = PdfWriter() for page in reader.pages: page.merge_page(watermark) writer.add_page(page) with open("watermarked.pdf", "wb") as output: writer.write(output) ``` ### Password Protection ```python from pypdf import PdfReader, PdfWriter reader = PdfReader("input.pdf") writer = PdfWriter() for page in reader.pages: writer.add_page(page) writer.encrypt("userpassword", "ownerpassword") with open("encrypted.pdf", "wb") as output: writer.write(output) ``` ### Create PDF with ReportLab ```python from reportlab.lib.pagesizes import letter from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak from reportlab.lib.styles import getSampleStyleSheet doc = SimpleDocTemplate("report.pdf", pagesize=letter) styles = getSampleStyleSheet() story = [] # Add content title = Paragraph("Report Title", styles['Title']) story.append(title) story.append(Spacer(1, 12)) body = Paragraph("This is the body of the report. " * 20, styles['Normal']) story.append(body) story.append(PageBreak()) # Page 2 story.append(Paragraph("Page 2", styles['Heading1'])) story.append(Paragraph("Content for page 2", styles['Normal'])) doc.build(story) ``` ### Command Line Tools ```bash # Extract text (poppler-utils) pdftotext input.pdf output.txt pdftotext -layout input.pdf output.txt # Preserve layout # Merge PDFs (qpdf) qpdf --empty --pages file1.pdf file2.pdf -- merged.pdf # Split pages qpdf input.pdf --pages . 1-5 -- pages1-5.pdf # Rotate pages qpdf input.pdf output.pdf --rotate=+90:1 # Remove password qpdf --password=mypassword --decrypt encrypted.pdf decrypted.pdf # Extract images pdfimages -j input.pdf output_prefix ``` --- ## Word Document (DOCX) Processing ### Text Extraction ```bash # Convert to markdown with pandoc pandoc document.docx -o output.md # With tracked changes preserved pandoc --track-changes=all document.docx -o output.md ``` ### Create New Document (docx-js) ```javascript import { Document, Paragraph, TextRun, HeadingLevel, Packer } from 'docx'; import * as fs from 'fs'; const doc = new Document({ sections: [{ properties: {}, children: [ new Paragraph({ text: "Document Title", heading: HeadingLevel.HEADING_1, }), new Paragraph({ children: [ new TextRun("This is a "), new TextRun({ text: "bold", bold: true, }), new TextRun(" word in a paragraph."), ], }), new Paragraph({ text: "This is another paragraph.", }), ], }], }); // Export to file const buffer = await Packer.toBuffer(doc); fs.writeFileSync("output.docx", buffer); ``` ### Create Document with Tables ```javascript import { Document, Paragraph, Table, TableRow, TableCell, Packer } from 'docx'; const table = new Table({ rows: [ new TableRow({ children: [ new TableCell({ children: [new Paragraph("Header 1")] }), new TableCell({ children: [new Paragraph("Header 2")] }), new TableCell({ children: [new Paragraph("Header 3")] }), ], }), new TableRow({ children: [ new TableCell({ children: [new Paragraph("Cell 1")] }), new TableCell({ children: [new Paragraph("Cell 2")] }), new TableCell({ children: [new Paragraph("Cell 3")] }), ], }), ], }); const doc = new Document({ sections: [{ children: [ new Paragraph({ text: "Table Example", heading: HeadingLevel.HEADING_1 }), table, ], }], }); ``` ### Edit Existing Document (OOXML) For complex edits, work with raw OOXML: 1. **Unpack the document:** ```bash python ooxml/scripts/unpack.py document.docx unpacked/ ``` 2. **Edit XML files** (primarily `word/document.xml`) 3. **Validate and pack:** ```bash python ooxml/scripts/validate.py unpacked/ --original document.docx python ooxml/scripts/pack.py unpacked/ output.docx ``` ### Tracked Changes Workflow For document review with track changes: ```bash # 1. Get current state pandoc --track-changes=all document.docx -o current.md # 2. Unpack python ooxml/scripts/unpack.py document.docx unpacked/ # 3. Edit using tracked change patterns # Use <w:ins> for insertions, <w:del> for deletions # 4. Pack final document python ooxml/scripts/pack.py unpacked/ reviewed.docx ``` --- ## PowerPoint (PPTX) Processing ### Text Extraction ```bash python -m markitdown presentation.pptx ``` ### Create New Presentation (PptxGenJS) ```javascript import PptxGenJS from 'pptxgenjs'; const pptx = new PptxGenJS(); // Slide 1 - Title const slide1 = pptx.addSlide(); slide1.addText("Presentation Title", { x: 1, y: 2, w: 8, h: 1.5, fontSize: 36, bold: true, color: "363636", align: "center", }); slide1.addText("Subtitle goes here", { x: 1, y: 3.5, w: 8, h: 0.5, fontSize: 18, color: "666666", align: "center", }); // Slide 2 - Content const slide2 = pptx.addSlide(); slide2.addText("Key Points", { x: 0.5, y: 0.5, w: 9, h: 0.8, fontSize: 28, bold: true, }); slide2.addText([ { text: "• First important point\n", options: { bullet: true } }, { text: "• Second important point\n", options: { bullet: true } }, { text: "• Third important point\n", options: { bullet: true } }, ], { x: 0.5, y: 1.5, w: 9, h: 3, fontSize: 18, }); // Slide 3 - Chart const slide3 = pptx.addSlide(); slide3.addChart(pptx.ChartType.bar, [ { name: "Q1", labels: ["Jan", "Feb", "Mar"], values: [100, 200, 300] }, { name: "Q2", labels: ["Apr", "May", "Jun"], values: [150, 250, 350] }, ], { x: 1, y: 1, w: 8, h: 4, showLegend: true, legendPos: "b", }); // Save pptx.writeFile("output.pptx"); ``` ### Edit Existing Presentation (OOXML) ```bash # 1. Unpack python ooxml/scripts/unpack.py presentation.pptx unpacked/ # 2. Key files: # - ppt/slides/slide1.xml, slide2.xml, etc. # - ppt/notesSlides/ for speaker notes # - ppt/theme/ for styling # 3. Validate and pack python ooxml/scripts/validate.py unpacked/ --original presentation.pptx python ooxml/scripts/pack.py unpacked/ output.pptx ``` ### Create Thumbnail Grid ```bash # Create visual overview of all slides python scripts/thumbnail.py presentation.pptx --cols 4 ``` ### Convert Slides to Images ```bash # Convert to PDF first soffice --headless --convert-to pdf presentation.pptx # Then PDF to images pdftoppm -jpeg -r 150 presentation.pdf slide # Creates slide-1.jpg, slide-2.jpg, etc. ``` --- ## Excel (XLSX) Processing ### Data Analysis with Pandas ```python import pandas as pd # Read Excel df = pd.read_excel('file.xlsx') # Default: first sheet all_sheets = pd.read_excel('file.xlsx', sheet_name=None) # All sheets as dict # Analyze df.head() # Preview data
在 GitHub 查看
这个 SKILL.md 很大,SkillsMP 这里只预览前一段内容。 在 GitHub 查看