This skill creates, edits, and analyzes PDF files.
Overview
It assists with reading PDFs, extracting text, processing forms, and creating new PDFs.
Main Features
- Text Extraction: Extract text and tables from PDFs
- PDF Generation: Create PDFs from HTML or Markdown
- Form Processing: Read and write PDF forms
- Split/Merge: Manipulate multiple PDFs
- Add Watermarks: Security Mark
- Password Protection: Create encrypted PDFs
- Metadata Editing: Title, author, etc.
Usage
Text Extraction
# Python + PyPDF2
import PyPDF2
with open('document.pdf', 'rb') as file:
reader = PyPDF2.PdfReader(file)
text = ''
for page in reader.pages:
text += page.extract_text()
print(text)
PDF Generation (from HTML)
# Python + pdfkit/weasyprint
import pdfkit
pdfkit.from_file('document.html', 'output.pdf')
# または
from weasyprint import HTML
HTML('document.html').write_pdf('output.pdf')
PDF Merging
from PyPDF2 import PdfMerger
merger = PdfMerger()
merger.append('file1.pdf')
merger.append('file2.pdf')
merger.write('combined.pdf')
merger.close()
Form Processing
from PyPDF2 import PdfReader, PdfWriter
reader = PdfReader('form.pdf')
writer = PdfWriter()
# フォームフィールドに値を設定
writer.add_page(reader.pages[0])
writer.update_page_form_field_values(
writer.pages[0],
{'name': 'John Doe', 'email': 'john@example.com'}
)
with open('filled_form.pdf', 'wb') as output:
writer.write(output)
JavaScript/Node.js
// pdf-lib
const { PDFDocument } = require('pdf-lib');
const fs = require('fs');
async function createPdf() {
const pdfDoc = await PDFDocument.create();
const page = pdfDoc.addPage([600, 400]);
page.drawText('Hello World!', {
x: 50,
y: 350,
size: 30
});
const pdfBytes = await pdfDoc.save();
fs.writeFileSync('output.pdf', pdfBytes);
}
Library
Python
- PyPDF2: PDF reading and writing
- pdfplumber: Table extraction
- ReportLab: PDF generation
- WeasyPrint: HTML→PDF
- pdfkit: wkhtmltopdf wrapper
JavaScript/Node.js
- pdf-lib: PDF creation and editing
- pdfjs-dist: PDF analysis
- puppeteer: HTML→PDF
- jsPDF: PDF generation in the browser
Go
- gofpdf: PDF generation
- unidoc: Commercial library
Version Information
- Skill Version: 1.0.0
- Last updated: 2025-01-22