51570f4da7
The bundled docx, xlsx, powerpoint, and pdf skills were adapted from Anthropic's document skills and carried their proprietary LICENSE.txt (no derivatives, no redistribution). Flagged as critical license findings by the SkillEvaluator Tier 1 scan of our skill tree. This replaces all four with clean-room rewrites: - Authored from scratch against library knowledge only (python-docx, openpyxl, python-pptx, pypdf/reportlab/pdfplumber — all MIT/BSD) by isolated subagents given functional specs, with an explicit prohibition on reading the prior skill content or anthropics/skills; session transcripts retained as provenance evidence. - MIT licensed (LICENSE file per skill), author: Nous Research. - Each skill: SKILL.md to house standards + argparse helper scripts with UTF-8-explicit I/O + its own e2e pytest suite (fixtures built on the fly, non-ASCII round-trips run under LC_ALL=C). - All four pass SkillEvaluator Tier 1 pii+unicode+lint 3/3. tests/skills/test_office_document_skills.py rewritten against the new contracts: MIT/no-Anthropic-text invariants, scripts documented in SKILL.md, argparse CLI shape, and a no-locale-default-open() check (which caught and fixed a real gap: pdfplumber text reads are fine, but the invariant scan now guards every future script). Docs pages regenerated for the four skills (scoped; unrelated generator drift excluded). Honest capability deltas vs the old versions are documented per SKILL.md (e.g. tracked-changes accept/reject and OOXML XSD validation are not reimplemented; form flattening limits stated).
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Stamp/watermark every page of a PDF with page 1 of another PDF."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
|
|
|
|
def main() -> int:
|
|
for stream in (sys.stdout, sys.stderr):
|
|
try:
|
|
stream.reconfigure(encoding="utf-8")
|
|
except Exception:
|
|
pass
|
|
parser = argparse.ArgumentParser(
|
|
description="Overlay (stamp) or underlay (watermark) a one-page PDF onto every page.")
|
|
parser.add_argument("pdf", help="Input PDF path")
|
|
parser.add_argument("--stamp", required=True, help="One-page PDF to apply (page 1 is used)")
|
|
parser.add_argument("-o", "--output", required=True, help="Output PDF path")
|
|
parser.add_argument("--under", action="store_true",
|
|
help="Place stamp under the page content (background watermark)")
|
|
parser.add_argument("--password", help="Password if the input is encrypted")
|
|
args = parser.parse_args()
|
|
|
|
try:
|
|
from pypdf import PdfReader, PdfWriter
|
|
except ImportError:
|
|
print("Missing dependency: install with 'python3 -m pip install pypdf'", file=sys.stderr)
|
|
return 2
|
|
|
|
reader = PdfReader(args.pdf)
|
|
if reader.is_encrypted:
|
|
if args.password is None or not reader.decrypt(args.password):
|
|
print("Error: input is encrypted; pass --password", file=sys.stderr)
|
|
return 3
|
|
stamp_page = PdfReader(args.stamp).pages[0]
|
|
|
|
writer = PdfWriter()
|
|
writer.append(reader)
|
|
for page in writer.pages:
|
|
page.merge_page(stamp_page, over=not args.under)
|
|
with open(args.output, "wb") as fh:
|
|
writer.write(fh)
|
|
print(json.dumps({"output": args.output, "page_count": len(writer.pages),
|
|
"mode": "under" if args.under else "over"}))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|