@nomad-e/bluma-cli 0.1.18 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/skills/git-commit/LICENSE.txt +18 -0
- package/dist/config/skills/git-commit/SKILL.md +258 -0
- package/dist/config/skills/git-commit/references/REFERENCE.md +249 -0
- package/dist/config/skills/git-commit/scripts/validate_commit_msg.py +163 -0
- package/dist/config/skills/git-pr/LICENSE.txt +18 -0
- package/dist/config/skills/git-pr/SKILL.md +293 -0
- package/dist/config/skills/git-pr/references/REFERENCE.md +256 -0
- package/dist/config/skills/git-pr/scripts/validate_commits.py +112 -0
- package/dist/config/skills/pdf/LICENSE.txt +26 -0
- package/dist/config/skills/pdf/SKILL.md +327 -0
- package/dist/config/skills/pdf/references/FORMS.md +69 -0
- package/dist/config/skills/pdf/references/REFERENCE.md +52 -0
- package/dist/config/skills/pdf/scripts/create_report.py +59 -0
- package/dist/config/skills/pdf/scripts/merge_pdfs.py +39 -0
- package/dist/config/skills/skill-creator/LICENSE.txt +26 -0
- package/dist/config/skills/skill-creator/SKILL.md +229 -0
- package/dist/config/skills/xlsx/LICENSE.txt +18 -0
- package/dist/config/skills/xlsx/SKILL.md +298 -0
- package/dist/config/skills/xlsx/references/REFERENCE.md +337 -0
- package/dist/config/skills/xlsx/scripts/office/__init__.py +2 -0
- package/dist/config/skills/xlsx/scripts/office/__pycache__/__init__.cpython-312.pyc +0 -0
- package/dist/config/skills/xlsx/scripts/office/__pycache__/pack.cpython-312.pyc +0 -0
- package/dist/config/skills/xlsx/scripts/office/__pycache__/soffice.cpython-312.pyc +0 -0
- package/dist/config/skills/xlsx/scripts/office/__pycache__/unpack.cpython-312.pyc +0 -0
- package/dist/config/skills/xlsx/scripts/office/__pycache__/validate.cpython-312.pyc +0 -0
- package/dist/config/skills/xlsx/scripts/office/pack.py +58 -0
- package/dist/config/skills/xlsx/scripts/office/soffice.py +180 -0
- package/dist/config/skills/xlsx/scripts/office/unpack.py +63 -0
- package/dist/config/skills/xlsx/scripts/office/validate.py +122 -0
- package/dist/config/skills/xlsx/scripts/recalc.py +143 -0
- package/dist/main.js +187 -46
- package/package.json +1 -1
- package/dist/config/example.bluma-mcp.json.txt +0 -14
- package/dist/config/models_config.json +0 -78
- package/dist/skills/git-conventional/LICENSE.txt +0 -3
- package/dist/skills/git-conventional/SKILL.md +0 -83
- package/dist/skills/skill-creator/SKILL.md +0 -495
- package/dist/skills/testing/LICENSE.txt +0 -3
- package/dist/skills/testing/SKILL.md +0 -114
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pdf
|
|
3
|
+
description: >
|
|
4
|
+
Use this skill for any task involving PDF files. Triggers include: creating
|
|
5
|
+
new PDFs from scratch, reading or extracting text and tables from PDFs,
|
|
6
|
+
merging or splitting PDFs, rotating pages, adding watermarks, encrypting or
|
|
7
|
+
decrypting PDFs, filling PDF forms, extracting images, and OCR on scanned
|
|
8
|
+
PDFs to make them searchable. Use this skill whenever the user mentions
|
|
9
|
+
.pdf, "PDF document", "create a report as PDF", "extract from PDF",
|
|
10
|
+
"merge PDFs", "split PDF", "protect PDF", "fill a form", or any
|
|
11
|
+
PDF-related task — even if not explicitly stated as such.
|
|
12
|
+
|
|
13
|
+
license: Proprietary. LICENSE.txt has complete terms
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# PDF Processing Guide
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
|
|
20
|
+
This guide covers essential PDF processing operations using Python libraries
|
|
21
|
+
and command-line tools. For advanced features, JavaScript libraries, and
|
|
22
|
+
detailed examples, see references/REFERENCE.md. If you need to fill out a
|
|
23
|
+
PDF form, read references/FORMS.md and follow its instructions.
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from pypdf import PdfReader, PdfWriter
|
|
29
|
+
|
|
30
|
+
# Read a PDF
|
|
31
|
+
reader = PdfReader("document.pdf")
|
|
32
|
+
print(f"Pages: {len(reader.pages)}")
|
|
33
|
+
|
|
34
|
+
# Extract text
|
|
35
|
+
text = ""
|
|
36
|
+
for page in reader.pages:
|
|
37
|
+
text += page.extract_text()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Python Libraries
|
|
41
|
+
|
|
42
|
+
### pypdf — Basic Operations
|
|
43
|
+
|
|
44
|
+
#### Merge PDFs
|
|
45
|
+
```python
|
|
46
|
+
from pypdf import PdfWriter, PdfReader
|
|
47
|
+
|
|
48
|
+
writer = PdfWriter()
|
|
49
|
+
for pdf_file in ["doc1.pdf", "doc2.pdf", "doc3.pdf"]:
|
|
50
|
+
reader = PdfReader(pdf_file)
|
|
51
|
+
for page in reader.pages:
|
|
52
|
+
writer.add_page(page)
|
|
53
|
+
|
|
54
|
+
with open("merged.pdf", "wb") as output:
|
|
55
|
+
writer.write(output)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### Split PDF
|
|
59
|
+
```python
|
|
60
|
+
reader = PdfReader("input.pdf")
|
|
61
|
+
for i, page in enumerate(reader.pages):
|
|
62
|
+
writer = PdfWriter()
|
|
63
|
+
writer.add_page(page)
|
|
64
|
+
with open(f"page_{i+1}.pdf", "wb") as output:
|
|
65
|
+
writer.write(output)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Extract Metadata
|
|
69
|
+
```python
|
|
70
|
+
reader = PdfReader("document.pdf")
|
|
71
|
+
meta = reader.metadata
|
|
72
|
+
print(f"Title: {meta.title}")
|
|
73
|
+
print(f"Author: {meta.author}")
|
|
74
|
+
print(f"Subject: {meta.subject}")
|
|
75
|
+
print(f"Creator: {meta.creator}")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### Rotate Pages
|
|
79
|
+
```python
|
|
80
|
+
reader = PdfReader("input.pdf")
|
|
81
|
+
writer = PdfWriter()
|
|
82
|
+
|
|
83
|
+
page = reader.pages[0]
|
|
84
|
+
page.rotate(90) # Rotate 90 degrees clockwise
|
|
85
|
+
writer.add_page(page)
|
|
86
|
+
|
|
87
|
+
with open("rotated.pdf", "wb") as output:
|
|
88
|
+
writer.write(output)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### pdfplumber — Text and Table Extraction
|
|
92
|
+
|
|
93
|
+
#### Extract Text with Layout
|
|
94
|
+
```python
|
|
95
|
+
import pdfplumber
|
|
96
|
+
|
|
97
|
+
with pdfplumber.open("document.pdf") as pdf:
|
|
98
|
+
for page in pdf.pages:
|
|
99
|
+
text = page.extract_text()
|
|
100
|
+
print(text)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### Extract Tables
|
|
104
|
+
```python
|
|
105
|
+
with pdfplumber.open("document.pdf") as pdf:
|
|
106
|
+
for i, page in enumerate(pdf.pages):
|
|
107
|
+
tables = page.extract_tables()
|
|
108
|
+
for j, table in enumerate(tables):
|
|
109
|
+
print(f"Table {j+1} on page {i+1}:")
|
|
110
|
+
for row in table:
|
|
111
|
+
print(row)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Advanced Table Extraction
|
|
115
|
+
```python
|
|
116
|
+
import pandas as pd
|
|
117
|
+
|
|
118
|
+
with pdfplumber.open("document.pdf") as pdf:
|
|
119
|
+
all_tables = []
|
|
120
|
+
for page in pdf.pages:
|
|
121
|
+
tables = page.extract_tables()
|
|
122
|
+
for table in tables:
|
|
123
|
+
if table:
|
|
124
|
+
df = pd.DataFrame(table[1:], columns=table[0])
|
|
125
|
+
all_tables.append(df)
|
|
126
|
+
|
|
127
|
+
if all_tables:
|
|
128
|
+
combined_df = pd.concat(all_tables, ignore_index=True)
|
|
129
|
+
combined_df.to_excel("extracted_tables.xlsx", index=False)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### reportlab — Create PDFs
|
|
133
|
+
|
|
134
|
+
#### Basic PDF Creation
|
|
135
|
+
```python
|
|
136
|
+
from reportlab.lib.pagesizes import A4
|
|
137
|
+
from reportlab.pdfgen import canvas
|
|
138
|
+
|
|
139
|
+
c = canvas.Canvas("hello.pdf", pagesize=A4)
|
|
140
|
+
width, height = A4
|
|
141
|
+
|
|
142
|
+
# Add text
|
|
143
|
+
c.drawString(100, height - 100, "Hello World!")
|
|
144
|
+
c.drawString(100, height - 120, "This is a PDF created with reportlab")
|
|
145
|
+
|
|
146
|
+
# Add a line
|
|
147
|
+
c.line(100, height - 140, 400, height - 140)
|
|
148
|
+
|
|
149
|
+
c.save()
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Create PDF with Multiple Pages
|
|
153
|
+
```python
|
|
154
|
+
from reportlab.lib.pagesizes import A4
|
|
155
|
+
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak
|
|
156
|
+
from reportlab.lib.styles import getSampleStyleSheet
|
|
157
|
+
|
|
158
|
+
doc = SimpleDocTemplate("report.pdf", pagesize=A4)
|
|
159
|
+
styles = getSampleStyleSheet()
|
|
160
|
+
story = []
|
|
161
|
+
|
|
162
|
+
# Add content
|
|
163
|
+
title = Paragraph("Report Title", styles['Title'])
|
|
164
|
+
story.append(title)
|
|
165
|
+
story.append(Spacer(1, 12))
|
|
166
|
+
|
|
167
|
+
body = Paragraph("This is the body of the report. " * 20, styles['Normal'])
|
|
168
|
+
story.append(body)
|
|
169
|
+
story.append(PageBreak())
|
|
170
|
+
|
|
171
|
+
# Page 2
|
|
172
|
+
story.append(Paragraph("Page 2", styles['Heading1']))
|
|
173
|
+
story.append(Paragraph("Content for page 2", styles['Normal']))
|
|
174
|
+
|
|
175
|
+
# Build PDF
|
|
176
|
+
doc.build(story)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### Subscripts and Superscripts
|
|
180
|
+
|
|
181
|
+
**IMPORTANT**: Never use Unicode subscript/superscript characters (₀₁₂₃₄₅₆₇₈₉,
|
|
182
|
+
⁰¹²³⁴⁵⁶⁷⁸⁹) in ReportLab PDFs. The built-in fonts do not include these glyphs,
|
|
183
|
+
causing them to render as solid black boxes.
|
|
184
|
+
|
|
185
|
+
pdftk file1.pdf file2.pdf cat output merged.pdf
|
|
186
|
+
|
|
187
|
+
# Split
|
|
188
|
+
pdftk input.pdf burst
|
|
189
|
+
from reportlab.lib.styles import getSampleStyleSheet
|
|
190
|
+
|
|
191
|
+
styles = getSampleStyleSheet()
|
|
192
|
+
|
|
193
|
+
# Subscripts: use <sub> tag
|
|
194
|
+
chemical = Paragraph("H<sub>2</sub>O", styles['Normal'])
|
|
195
|
+
|
|
196
|
+
# Superscripts: use <super> tag
|
|
197
|
+
squared = Paragraph("x<super>2</super> + y<super>2</super>", styles['Normal'])
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
For canvas-drawn text (not Paragraph objects), manually adjust font size and
|
|
201
|
+
position rather than using Unicode subscripts/superscripts.
|
|
202
|
+
|
|
203
|
+
## Command-Line Tools
|
|
204
|
+
|
|
205
|
+
### pdftotext (poppler-utils)
|
|
206
|
+
```bash
|
|
207
|
+
# Extract text
|
|
208
|
+
pdftotext input.pdf output.txt
|
|
209
|
+
|
|
210
|
+
# Extract text preserving layout
|
|
211
|
+
pdftotext -layout input.pdf output.txt
|
|
212
|
+
|
|
213
|
+
# Extract specific pages
|
|
214
|
+
pdftotext -f 1 -l 5 input.pdf output.txt # Pages 1-5
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### qpdf
|
|
218
|
+
```bash
|
|
219
|
+
# Merge PDFs
|
|
220
|
+
qpdf --empty --pages file1.pdf file2.pdf -- merged.pdf
|
|
221
|
+
|
|
222
|
+
# Split pages
|
|
223
|
+
qpdf input.pdf --pages . 1-5 -- pages1-5.pdf
|
|
224
|
+
qpdf input.pdf --pages . 6-10 -- pages6-10.pdf
|
|
225
|
+
|
|
226
|
+
# Rotate pages
|
|
227
|
+
qpdf input.pdf output.pdf --rotate=+90:1 # Rotate page 1 by 90 degrees
|
|
228
|
+
|
|
229
|
+
# Remove password
|
|
230
|
+
qpdf --password=mypassword --decrypt encrypted.pdf decrypted.pdf
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### pdftk (if available)
|
|
234
|
+
```bash
|
|
235
|
+
# Merge
|
|
236
|
+
pdftk file1.pdf file2.pdf cat output merged.pdf
|
|
237
|
+
|
|
238
|
+
# Split
|
|
239
|
+
pdftk input.pdf burst
|
|
240
|
+
|
|
241
|
+
# Rotate
|
|
242
|
+
pdftk input.pdf rotate 1east output rotated.pdf
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Common Tasks
|
|
246
|
+
|
|
247
|
+
### Extract Text from Scanned PDFs
|
|
248
|
+
```python
|
|
249
|
+
# Requires: pip install pytesseract pdf2image
|
|
250
|
+
import pytesseract
|
|
251
|
+
from pdf2image import convert_from_path
|
|
252
|
+
|
|
253
|
+
# Convert PDF to images
|
|
254
|
+
images = convert_from_path('scanned.pdf')
|
|
255
|
+
|
|
256
|
+
# OCR each page
|
|
257
|
+
text = ""
|
|
258
|
+
for i, image in enumerate(images):
|
|
259
|
+
text += f"Page {i+1}:\n"
|
|
260
|
+
text += pytesseract.image_to_string(image, lang="por+eng")
|
|
261
|
+
text += "\n\n"
|
|
262
|
+
|
|
263
|
+
print(text)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Add Watermark
|
|
267
|
+
```python
|
|
268
|
+
from pypdf import PdfReader, PdfWriter
|
|
269
|
+
|
|
270
|
+
# Load watermark
|
|
271
|
+
watermark = PdfReader("watermark.pdf").pages[0]
|
|
272
|
+
|
|
273
|
+
# Apply to all pages
|
|
274
|
+
reader = PdfReader("document.pdf")
|
|
275
|
+
writer = PdfWriter()
|
|
276
|
+
|
|
277
|
+
for page in reader.pages:
|
|
278
|
+
page.merge_page(watermark)
|
|
279
|
+
writer.add_page(page)
|
|
280
|
+
|
|
281
|
+
with open("watermarked.pdf", "wb") as output:
|
|
282
|
+
writer.write(output)
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Extract Images
|
|
286
|
+
```bash
|
|
287
|
+
# Using pdfimages (poppler-utils)
|
|
288
|
+
pdfimages -j input.pdf output_prefix
|
|
289
|
+
# Extracts all images as output_prefix-000.jpg, output_prefix-001.jpg, etc.
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Password Protection
|
|
293
|
+
```python
|
|
294
|
+
from pypdf import PdfReader, PdfWriter
|
|
295
|
+
|
|
296
|
+
reader = PdfReader("input.pdf")
|
|
297
|
+
writer = PdfWriter()
|
|
298
|
+
|
|
299
|
+
for page in reader.pages:
|
|
300
|
+
writer.add_page(page)
|
|
301
|
+
|
|
302
|
+
# Add password
|
|
303
|
+
writer.encrypt("userpassword", "ownerpassword")
|
|
304
|
+
|
|
305
|
+
with open("encrypted.pdf", "wb") as output:
|
|
306
|
+
writer.write(output)
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Quick Reference
|
|
310
|
+
|
|
311
|
+
| Task | Best Tool | Command/Code |
|
|
312
|
+
|-----------------------|--------------|-------------------------------------|
|
|
313
|
+
| Merge PDFs | pypdf | `writer.add_page(page)` |
|
|
314
|
+
| Split PDFs | pypdf | One page per file |
|
|
315
|
+
| Extract text | pdfplumber | `page.extract_text()` |
|
|
316
|
+
| Extract tables | pdfplumber | `page.extract_tables()` |
|
|
317
|
+
| Create PDFs | reportlab | Canvas or Platypus |
|
|
318
|
+
| Command line merge | qpdf | `qpdf --empty --pages ...` |
|
|
319
|
+
| OCR scanned PDFs | pytesseract | Convert to image first |
|
|
320
|
+
| Fill PDF forms | pypdf / pdf-lib (see FORMS.md) | See references/FORMS.md |
|
|
321
|
+
|
|
322
|
+
## Next Steps
|
|
323
|
+
|
|
324
|
+
- For advanced pypdfium2 usage, see references/REFERENCE.md
|
|
325
|
+
- For JavaScript libraries (pdf-lib), see references/REFERENCE.md
|
|
326
|
+
- If you need to fill out a PDF form, follow the instructions in references/FORMS.md
|
|
327
|
+
- For troubleshooting guides, see references/REFERENCE.md
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# PDF Forms — Filling and Processing Guide
|
|
2
|
+
|
|
3
|
+
This reference covers PDF form filling using Python and JavaScript libraries.
|
|
4
|
+
|
|
5
|
+
## Detecting Form Fields (Python)
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from pypdf import PdfReader
|
|
9
|
+
|
|
10
|
+
reader = PdfReader("form.pdf")
|
|
11
|
+
fields = reader.get_fields()
|
|
12
|
+
for name, field in fields.items():
|
|
13
|
+
print(f"Field: {name}, Type: {field.get('/FT')}, Value: {field.get('/V')}")
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Filling Forms with pypdf
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from pypdf import PdfReader, PdfWriter
|
|
20
|
+
|
|
21
|
+
reader = PdfReader("form.pdf")
|
|
22
|
+
writer = PdfWriter()
|
|
23
|
+
writer.append(reader)
|
|
24
|
+
|
|
25
|
+
writer.update_page_form_field_values(
|
|
26
|
+
writer.pages[0],
|
|
27
|
+
{
|
|
28
|
+
"name_field": "John Doe",
|
|
29
|
+
"email_field": "john@example.com",
|
|
30
|
+
"date_field": "2026-01-15",
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
with open("filled_form.pdf", "wb") as output:
|
|
35
|
+
writer.write(output)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Filling Forms with pdf-lib (JavaScript)
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
import { PDFDocument } from 'pdf-lib';
|
|
42
|
+
import fs from 'fs';
|
|
43
|
+
|
|
44
|
+
const pdfBytes = fs.readFileSync('form.pdf');
|
|
45
|
+
const pdfDoc = await PDFDocument.load(pdfBytes);
|
|
46
|
+
const form = pdfDoc.getForm();
|
|
47
|
+
|
|
48
|
+
form.getTextField('name').setText('John Doe');
|
|
49
|
+
form.getTextField('email').setText('john@example.com');
|
|
50
|
+
form.getCheckBox('agree').check();
|
|
51
|
+
|
|
52
|
+
const filledBytes = await pdfDoc.save();
|
|
53
|
+
fs.writeFileSync('filled_form.pdf', filledBytes);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Common Form Field Types
|
|
57
|
+
|
|
58
|
+
| Type | pypdf Code | pdf-lib Code |
|
|
59
|
+
|------|-----------|-------------|
|
|
60
|
+
| Text | `update_page_form_field_values` | `getTextField().setText()` |
|
|
61
|
+
| Checkbox | Set to `/Yes` or `/Off` | `getCheckBox().check()` |
|
|
62
|
+
| Radio | Set to option value | `getRadioGroup().select()` |
|
|
63
|
+
| Dropdown | Set to option value | `getDropdown().select()` |
|
|
64
|
+
|
|
65
|
+
## Tips
|
|
66
|
+
|
|
67
|
+
- Always flatten forms after filling if the PDF will be shared (prevents editing).
|
|
68
|
+
- Some PDFs have XFA forms (XML-based) which are harder to fill programmatically.
|
|
69
|
+
- For XFA forms, consider using pdftk or a commercial library.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# PDF Processing — Advanced Reference
|
|
2
|
+
|
|
3
|
+
This document covers advanced PDF processing techniques beyond the basics in SKILL.md.
|
|
4
|
+
|
|
5
|
+
## pypdfium2 — High-Performance Rendering
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
import pypdfium2 as pdfium
|
|
9
|
+
|
|
10
|
+
pdf = pdfium.PdfDocument("document.pdf")
|
|
11
|
+
for i, page in enumerate(pdf):
|
|
12
|
+
bitmap = page.render(scale=2)
|
|
13
|
+
image = bitmap.to_pil()
|
|
14
|
+
image.save(f"page_{i+1}.png")
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## JavaScript Libraries (pdf-lib)
|
|
18
|
+
|
|
19
|
+
For browser-based or Node.js PDF manipulation:
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { PDFDocument } from 'pdf-lib';
|
|
23
|
+
|
|
24
|
+
const pdfDoc = await PDFDocument.create();
|
|
25
|
+
const page = pdfDoc.addPage([600, 400]);
|
|
26
|
+
page.drawText('Hello, PDF!', { x: 50, y: 350, size: 30 });
|
|
27
|
+
const pdfBytes = await pdfDoc.save();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## pdf-lib — Modify Existing PDFs
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
import { PDFDocument } from 'pdf-lib';
|
|
34
|
+
import fs from 'fs';
|
|
35
|
+
|
|
36
|
+
const existingPdfBytes = fs.readFileSync('input.pdf');
|
|
37
|
+
const pdfDoc = await PDFDocument.load(existingPdfBytes);
|
|
38
|
+
const pages = pdfDoc.getPages();
|
|
39
|
+
const firstPage = pages[0];
|
|
40
|
+
firstPage.drawText('WATERMARK', { x: 200, y: 400, size: 50, opacity: 0.3 });
|
|
41
|
+
const pdfBytes = await pdfDoc.save();
|
|
42
|
+
fs.writeFileSync('output.pdf', pdfBytes);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Troubleshooting
|
|
46
|
+
|
|
47
|
+
| Issue | Solution |
|
|
48
|
+
|-------|----------|
|
|
49
|
+
| "PdfReadError: EOF marker not found" | File is corrupted or not a valid PDF |
|
|
50
|
+
| Empty text extraction | PDF might be image-based; use OCR (pytesseract) |
|
|
51
|
+
| Tables not extracted correctly | Adjust pdfplumber table settings or try camelot |
|
|
52
|
+
| Large PDF processing slow | Process pages in chunks or use pypdfium2 |
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Create a simple PDF report from CSV data using reportlab.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
python create_report.py --input data.csv --output ./artifacts/report.pdf
|
|
6
|
+
python create_report.py --input data.csv --output report.pdf --title "Sales Report Q1 2026"
|
|
7
|
+
"""
|
|
8
|
+
import argparse
|
|
9
|
+
import csv
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
def create_report(input_csv: str, output_pdf: str, title: str = "Report") -> None:
|
|
13
|
+
try:
|
|
14
|
+
from reportlab.lib.pagesizes import A4
|
|
15
|
+
from reportlab.lib import colors
|
|
16
|
+
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer
|
|
17
|
+
from reportlab.lib.styles import getSampleStyleSheet
|
|
18
|
+
except ImportError:
|
|
19
|
+
print("Error: reportlab is required. Install with: pip install reportlab", file=sys.stderr)
|
|
20
|
+
sys.exit(1)
|
|
21
|
+
|
|
22
|
+
with open(input_csv, "r", encoding="utf-8") as f:
|
|
23
|
+
reader = csv.reader(f)
|
|
24
|
+
data = list(reader)
|
|
25
|
+
|
|
26
|
+
if not data:
|
|
27
|
+
print("Error: CSV file is empty", file=sys.stderr)
|
|
28
|
+
sys.exit(1)
|
|
29
|
+
|
|
30
|
+
doc = SimpleDocTemplate(output_pdf, pagesize=A4)
|
|
31
|
+
styles = getSampleStyleSheet()
|
|
32
|
+
elements = []
|
|
33
|
+
|
|
34
|
+
elements.append(Paragraph(title, styles["Title"]))
|
|
35
|
+
elements.append(Spacer(1, 20))
|
|
36
|
+
|
|
37
|
+
table = Table(data)
|
|
38
|
+
table.setStyle(TableStyle([
|
|
39
|
+
("BACKGROUND", (0, 0), (-1, 0), colors.grey),
|
|
40
|
+
("TEXTCOLOR", (0, 0), (-1, 0), colors.whitesmoke),
|
|
41
|
+
("ALIGN", (0, 0), (-1, -1), "CENTER"),
|
|
42
|
+
("FONTNAME", (0, 0), (-1, 0), "Helvetica-Bold"),
|
|
43
|
+
("FONTSIZE", (0, 0), (-1, 0), 12),
|
|
44
|
+
("BOTTOMPADDING", (0, 0), (-1, 0), 12),
|
|
45
|
+
("BACKGROUND", (0, 1), (-1, -1), colors.beige),
|
|
46
|
+
("GRID", (0, 0), (-1, -1), 1, colors.black),
|
|
47
|
+
]))
|
|
48
|
+
elements.append(table)
|
|
49
|
+
|
|
50
|
+
doc.build(elements)
|
|
51
|
+
print(f"Report created: {output_pdf} ({len(data)-1} data rows)")
|
|
52
|
+
|
|
53
|
+
if __name__ == "__main__":
|
|
54
|
+
parser = argparse.ArgumentParser(description="Create PDF report from CSV")
|
|
55
|
+
parser.add_argument("--input", "-i", required=True, help="Input CSV file")
|
|
56
|
+
parser.add_argument("--output", "-o", required=True, help="Output PDF path")
|
|
57
|
+
parser.add_argument("--title", "-t", default="Report", help="Report title")
|
|
58
|
+
args = parser.parse_args()
|
|
59
|
+
create_report(args.input, args.output, args.title)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Merge multiple PDF files into a single output PDF.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
python merge_pdfs.py --output merged.pdf file1.pdf file2.pdf file3.pdf
|
|
6
|
+
python merge_pdfs.py --output ./artifacts/combined.pdf *.pdf
|
|
7
|
+
"""
|
|
8
|
+
import argparse
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
def merge_pdfs(input_files: list[str], output_path: str) -> None:
|
|
12
|
+
try:
|
|
13
|
+
from pypdf import PdfWriter, PdfReader
|
|
14
|
+
except ImportError:
|
|
15
|
+
print("Error: pypdf is required. Install with: pip install pypdf", file=sys.stderr)
|
|
16
|
+
sys.exit(1)
|
|
17
|
+
|
|
18
|
+
writer = PdfWriter()
|
|
19
|
+
for pdf_file in input_files:
|
|
20
|
+
try:
|
|
21
|
+
reader = PdfReader(pdf_file)
|
|
22
|
+
for page in reader.pages:
|
|
23
|
+
writer.add_page(page)
|
|
24
|
+
print(f"Added: {pdf_file} ({len(reader.pages)} pages)")
|
|
25
|
+
except Exception as e:
|
|
26
|
+
print(f"Error reading {pdf_file}: {e}", file=sys.stderr)
|
|
27
|
+
sys.exit(1)
|
|
28
|
+
|
|
29
|
+
with open(output_path, "wb") as f:
|
|
30
|
+
writer.write(f)
|
|
31
|
+
|
|
32
|
+
print(f"Merged {len(input_files)} files -> {output_path}")
|
|
33
|
+
|
|
34
|
+
if __name__ == "__main__":
|
|
35
|
+
parser = argparse.ArgumentParser(description="Merge PDF files")
|
|
36
|
+
parser.add_argument("files", nargs="+", help="PDF files to merge")
|
|
37
|
+
parser.add_argument("--output", "-o", required=True, help="Output file path")
|
|
38
|
+
args = parser.parse_args()
|
|
39
|
+
merge_pdfs(args.files, args.output)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
© 2026 NomadEngenuity LDA. All rights reserved.
|
|
2
|
+
|
|
3
|
+
LICENSE: Use of these materials (including all code, prompts, assets, files,
|
|
4
|
+
and other components of this Skill) is governed by your agreement with
|
|
5
|
+
NomadEngenuity LDA regarding use of NomadEngenuity LDA's services. If no
|
|
6
|
+
separate agreement exists, use is governed by NomadEngenuity LDA's applicable
|
|
7
|
+
Terms of Service.
|
|
8
|
+
|
|
9
|
+
ADDITIONAL RESTRICTIONS: Notwithstanding anything in the Agreement to the
|
|
10
|
+
contrary, users may not:
|
|
11
|
+
|
|
12
|
+
- Extract these materials from the Services or retain copies of these
|
|
13
|
+
materials outside the Services
|
|
14
|
+
- Reproduce or copy these materials, except for temporary copies created
|
|
15
|
+
automatically during authorized use of the Services
|
|
16
|
+
- Create derivative works based on these materials
|
|
17
|
+
- Distribute, sublicense, or transfer these materials to any third party
|
|
18
|
+
- Make, offer to sell, sell, or import any inventions embodied in these
|
|
19
|
+
materials
|
|
20
|
+
- Reverse engineer, decompile, or disassemble these materials
|
|
21
|
+
|
|
22
|
+
The receipt, viewing, or possession of these materials does not convey or
|
|
23
|
+
imply any license or right beyond those expressly granted above.
|
|
24
|
+
|
|
25
|
+
NomadEngenuity LDA retains all right, title, and interest in these materials,
|
|
26
|
+
including all copyrights, patents, and other intellectual property rights.
|