@panda-agent/panda-cli 0.1.29 → 0.1.30
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/panda-cli-ink.bundle.mjs +258 -247
- package/package.json +6 -4
- package/skills/.gitkeep +0 -0
- package/skills/README.md +13 -0
- package/skills/docx/.skill-metadata.yaml +173 -0
- package/skills/docx/LICENSE.txt +30 -0
- package/skills/docx/SKILL.md +589 -0
- package/skills/docx/scripts/__init__.py +1 -0
- package/skills/docx/scripts/accept_changes.py +206 -0
- package/skills/docx/scripts/comment.py +442 -0
- package/skills/docx/scripts/office/helpers/__init__.py +1 -0
- package/skills/docx/scripts/office/helpers/merge_runs.py +190 -0
- package/skills/docx/scripts/office/helpers/simplify_redlines.py +185 -0
- package/skills/docx/scripts/office/pack.py +167 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/docx/scripts/office/schemas/mce/mc.xsd +75 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/docx/scripts/office/soffice.py +194 -0
- package/skills/docx/scripts/office/unpack.py +145 -0
- package/skills/docx/scripts/office/validate.py +114 -0
- package/skills/docx/scripts/office/validators/__init__.py +16 -0
- package/skills/docx/scripts/office/validators/base.py +733 -0
- package/skills/docx/scripts/office/validators/docx.py +354 -0
- package/skills/docx/scripts/office/validators/pptx.py +230 -0
- package/skills/docx/scripts/office/validators/redlining.py +212 -0
- package/skills/docx/scripts/templates/comments.xml +3 -0
- package/skills/docx/scripts/templates/commentsExtended.xml +3 -0
- package/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
- package/skills/docx/scripts/templates/commentsIds.xml +3 -0
- package/skills/docx/scripts/templates/people.xml +3 -0
- package/skills/frontend-design/LICENSE.txt +177 -0
- package/skills/frontend-design/SKILL.md +42 -0
- package/skills/pdf/.skill-metadata.yaml +273 -0
- package/skills/pdf/LICENSE.txt +30 -0
- package/skills/pdf/SKILL.md +324 -0
- package/skills/pdf/advanced-reference.md +609 -0
- package/skills/pdf/form-filling-guide.md +318 -0
- package/skills/pdf/forms.md +294 -0
- package/skills/pdf/reference.md +612 -0
- package/skills/pdf/scripts/check_bounding_boxes.py +198 -0
- package/skills/pdf/scripts/check_fillable_fields.py +64 -0
- package/skills/pdf/scripts/convert_pdf_to_images.py +102 -0
- package/skills/pdf/scripts/create_validation_image.py +125 -0
- package/skills/pdf/scripts/extract_form_field_info.py +220 -0
- package/skills/pdf/scripts/extract_form_structure.py +202 -0
- package/skills/pdf/scripts/fill_fillable_fields.py +205 -0
- package/skills/pdf/scripts/fill_pdf_form_with_annotations.py +193 -0
- package/skills/pptx-generator/SKILL.md +204 -0
- package/skills/pptx-generator/assets/styles/business.json +8 -0
- package/skills/pptx-generator/assets/styles/minimal.json +8 -0
- package/skills/pptx-generator/assets/styles/modern.json +8 -0
- package/skills/pptx-generator/assets/templates/ppt_data_template.json +40 -0
- package/skills/pptx-generator/references/collaboration_guide.md +381 -0
- package/skills/pptx-generator/references/json_format_spec.md +215 -0
- package/skills/pptx-generator/references/layout_guide.md +290 -0
- package/skills/pptx-generator/scripts/json_validator.py +194 -0
- package/skills/pptx-generator/scripts/pptx_builder.py +340 -0
- package/skills/pptx-generator/scripts/pptx_validator.py +162 -0
- package/skills/skill-creator/LICENSE.txt +202 -0
- package/skills/skill-creator/SKILL.md +479 -0
- package/skills/skill-creator/agents/analyzer.md +274 -0
- package/skills/skill-creator/agents/comparator.md +202 -0
- package/skills/skill-creator/agents/grader.md +223 -0
- package/skills/skill-creator/assets/eval_review.html +146 -0
- package/skills/skill-creator/eval-viewer/generate_review.py +471 -0
- package/skills/skill-creator/eval-viewer/viewer.html +1325 -0
- package/skills/skill-creator/references/schemas.md +430 -0
- package/skills/skill-creator/scripts/__init__.py +0 -0
- package/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
- package/skills/skill-creator/scripts/generate_report.py +326 -0
- package/skills/skill-creator/scripts/improve_description.py +248 -0
- package/skills/skill-creator/scripts/package_skill.py +136 -0
- package/skills/skill-creator/scripts/quick_validate.py +103 -0
- package/skills/skill-creator/scripts/run_eval.py +310 -0
- package/skills/skill-creator/scripts/run_loop.py +332 -0
- package/skills/skill-creator/scripts/utils.py +47 -0
- package/skills/xlsx/.skill-metadata.yaml +185 -0
- package/skills/xlsx/LICENSE.txt +30 -0
- package/skills/xlsx/SKILL.md +233 -0
- package/skills/xlsx/scripts/office/helpers/__init__.py +1 -0
- package/skills/xlsx/scripts/office/helpers/merge_runs.py +226 -0
- package/skills/xlsx/scripts/office/helpers/simplify_redlines.py +198 -0
- package/skills/xlsx/scripts/office/pack.py +162 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/xlsx/scripts/office/schemas/mce/mc.xsd +75 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/xlsx/scripts/office/soffice.py +185 -0
- package/skills/xlsx/scripts/office/unpack.py +146 -0
- package/skills/xlsx/scripts/office/validate.py +108 -0
- package/skills/xlsx/scripts/office/validators/__init__.py +13 -0
- package/skills/xlsx/scripts/office/validators/base.py +800 -0
- package/skills/xlsx/scripts/office/validators/docx.py +383 -0
- package/skills/xlsx/scripts/office/validators/pptx.py +250 -0
- package/skills/xlsx/scripts/office/validators/redlining.py +229 -0
- package/skills/xlsx/scripts/recalc.py +296 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"""Place text onto a PDF using FreeText annotations, guided by a JSON
|
|
2
|
+
coordinate specification.
|
|
3
|
+
|
|
4
|
+
Supports both image-pixel and native PDF coordinate inputs with automatic
|
|
5
|
+
conversion.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
python fill_pdf_form_with_annotations.py <input.pdf> <fields.json> <output.pdf>
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import json
|
|
13
|
+
import sys
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any, Dict, List, Tuple
|
|
16
|
+
|
|
17
|
+
import pypdf
|
|
18
|
+
from pypdf.annotations import FreeText as TextAnnotation
|
|
19
|
+
|
|
20
|
+
# ---------------------------------------------------------------------------
|
|
21
|
+
# Constants
|
|
22
|
+
# ---------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
EXIT_SUCCESS: int = 0
|
|
25
|
+
EXIT_FAILURE: int = 1
|
|
26
|
+
|
|
27
|
+
DEFAULT_FONT: str = "Arial"
|
|
28
|
+
DEFAULT_SIZE: int = 14
|
|
29
|
+
DEFAULT_COLOR: str = "000000"
|
|
30
|
+
|
|
31
|
+
# ---------------------------------------------------------------------------
|
|
32
|
+
# Coordinate transformation
|
|
33
|
+
# ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _pixel_to_pdf_rect(
|
|
37
|
+
box: List[float],
|
|
38
|
+
img_w: float,
|
|
39
|
+
img_h: float,
|
|
40
|
+
doc_w: float,
|
|
41
|
+
doc_h: float,
|
|
42
|
+
) -> Tuple[float, float, float, float]:
|
|
43
|
+
"""Map image-space pixel coordinates to PDF annotation coordinates."""
|
|
44
|
+
sx: float = doc_w / img_w
|
|
45
|
+
sy: float = doc_h / img_h
|
|
46
|
+
pdf_left: float = box[0] * sx
|
|
47
|
+
pdf_right: float = box[2] * sx
|
|
48
|
+
pdf_top: float = doc_h - (box[1] * sy)
|
|
49
|
+
pdf_bottom: float = doc_h - (box[3] * sy)
|
|
50
|
+
return pdf_left, pdf_bottom, pdf_right, pdf_top
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _native_to_pypdf_rect(
|
|
54
|
+
box: List[float],
|
|
55
|
+
doc_h: float,
|
|
56
|
+
) -> Tuple[float, float, float, float]:
|
|
57
|
+
"""Convert PDF-native coordinates (y=0 at top) to pypdf annotation rect."""
|
|
58
|
+
left: float = box[0]
|
|
59
|
+
right: float = box[2]
|
|
60
|
+
pypdf_top: float = doc_h - box[1]
|
|
61
|
+
pypdf_bottom: float = doc_h - box[3]
|
|
62
|
+
return left, pypdf_bottom, right, pypdf_top
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# ---------------------------------------------------------------------------
|
|
66
|
+
# Core logic
|
|
67
|
+
# ---------------------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def annotate_pdf(src_path: Path, spec_path: Path, out_path: Path) -> None:
|
|
71
|
+
"""Read the coordinate spec, add FreeText annotations to each field,
|
|
72
|
+
and write the result to *out_path*.
|
|
73
|
+
"""
|
|
74
|
+
with open(spec_path, "r", encoding="utf-8") as fh:
|
|
75
|
+
spec: Dict[str, Any] = json.load(fh)
|
|
76
|
+
|
|
77
|
+
source = pypdf.PdfReader(str(src_path))
|
|
78
|
+
output = pypdf.PdfWriter()
|
|
79
|
+
output.append(source)
|
|
80
|
+
|
|
81
|
+
# Cache actual page dimensions from the source PDF
|
|
82
|
+
actual_dims: Dict[int, Tuple[float, float]] = {}
|
|
83
|
+
for idx, pg in enumerate(source.pages):
|
|
84
|
+
mb = pg.mediabox
|
|
85
|
+
actual_dims[idx + 1] = (float(mb.width), float(mb.height))
|
|
86
|
+
|
|
87
|
+
annotation_count: int = 0
|
|
88
|
+
|
|
89
|
+
for fld in spec["form_fields"]:
|
|
90
|
+
pg_num: int = fld["page_number"]
|
|
91
|
+
pg_meta: Dict[str, Any] = next(
|
|
92
|
+
p for p in spec["pages"] if p["page_number"] == pg_num
|
|
93
|
+
)
|
|
94
|
+
real_w, real_h = actual_dims[pg_num]
|
|
95
|
+
|
|
96
|
+
# Determine coordinate system and transform
|
|
97
|
+
use_pdf_coords: bool = "pdf_width" in pg_meta
|
|
98
|
+
if use_pdf_coords:
|
|
99
|
+
rect = _native_to_pypdf_rect(fld["entry_bounding_box"], real_h)
|
|
100
|
+
else:
|
|
101
|
+
rect = _pixel_to_pdf_rect(
|
|
102
|
+
fld["entry_bounding_box"],
|
|
103
|
+
pg_meta["image_width"],
|
|
104
|
+
pg_meta["image_height"],
|
|
105
|
+
real_w,
|
|
106
|
+
real_h,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
# Skip fields without text content
|
|
110
|
+
txt_spec = fld.get("entry_text")
|
|
111
|
+
if txt_spec is None or "text" not in txt_spec:
|
|
112
|
+
continue
|
|
113
|
+
content: str = txt_spec["text"]
|
|
114
|
+
if not content:
|
|
115
|
+
continue
|
|
116
|
+
|
|
117
|
+
# Build annotation with styling
|
|
118
|
+
face: str = txt_spec.get("font", DEFAULT_FONT)
|
|
119
|
+
size_str: str = "%spt" % txt_spec.get("font_size", DEFAULT_SIZE)
|
|
120
|
+
color: str = txt_spec.get("font_color", DEFAULT_COLOR)
|
|
121
|
+
|
|
122
|
+
ann = TextAnnotation(
|
|
123
|
+
text=content,
|
|
124
|
+
rect=rect,
|
|
125
|
+
font=face,
|
|
126
|
+
font_size=size_str,
|
|
127
|
+
font_color=color,
|
|
128
|
+
border_color=None,
|
|
129
|
+
background_color=None,
|
|
130
|
+
)
|
|
131
|
+
output.add_annotation(page_number=pg_num - 1, annotation=ann)
|
|
132
|
+
annotation_count += 1
|
|
133
|
+
|
|
134
|
+
with open(out_path, "wb") as dest:
|
|
135
|
+
output.write(dest)
|
|
136
|
+
|
|
137
|
+
print("Successfully filled PDF form and saved to %s" % out_path)
|
|
138
|
+
print("Added %d text annotations" % annotation_count)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
# ---------------------------------------------------------------------------
|
|
142
|
+
# CLI
|
|
143
|
+
# ---------------------------------------------------------------------------
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
147
|
+
"""Construct the CLI argument parser."""
|
|
148
|
+
parser = argparse.ArgumentParser(
|
|
149
|
+
description=(
|
|
150
|
+
"Fill a PDF form by placing FreeText annotations at coordinates "
|
|
151
|
+
"specified in a JSON file."
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
parser.add_argument(
|
|
155
|
+
"input_pdf",
|
|
156
|
+
type=Path,
|
|
157
|
+
help="Path to the source PDF document.",
|
|
158
|
+
)
|
|
159
|
+
parser.add_argument(
|
|
160
|
+
"fields_json",
|
|
161
|
+
type=Path,
|
|
162
|
+
help="JSON specification with field coordinates and text.",
|
|
163
|
+
)
|
|
164
|
+
parser.add_argument(
|
|
165
|
+
"output_pdf",
|
|
166
|
+
type=Path,
|
|
167
|
+
help="Destination path for the annotated PDF.",
|
|
168
|
+
)
|
|
169
|
+
return parser
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def main() -> None:
|
|
173
|
+
"""Entry point: parse arguments and annotate PDF."""
|
|
174
|
+
parser = build_parser()
|
|
175
|
+
args = parser.parse_args()
|
|
176
|
+
|
|
177
|
+
input_pdf: Path = args.input_pdf
|
|
178
|
+
fields_json: Path = args.fields_json
|
|
179
|
+
output_pdf: Path = args.output_pdf
|
|
180
|
+
|
|
181
|
+
if not input_pdf.exists():
|
|
182
|
+
print("ERROR: File not found: {}".format(input_pdf), file=sys.stderr)
|
|
183
|
+
sys.exit(EXIT_FAILURE)
|
|
184
|
+
|
|
185
|
+
if not fields_json.exists():
|
|
186
|
+
print("ERROR: File not found: {}".format(fields_json), file=sys.stderr)
|
|
187
|
+
sys.exit(EXIT_FAILURE)
|
|
188
|
+
|
|
189
|
+
annotate_pdf(input_pdf, fields_json, output_pdf)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
if __name__ == "__main__":
|
|
193
|
+
main()
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pptx-generator
|
|
3
|
+
description: 将 JSON 格式的 PPT 内容转换为标准的 .pptx 文件。使用 python-pptx 库,支持多种布局、图表、表格和样式。与 ppt-generator Skill 完全协同,可作为独立使用或与其他 PPT Skill 配合。
|
|
4
|
+
dependency:
|
|
5
|
+
python:
|
|
6
|
+
- python-pptx>=1.0.2
|
|
7
|
+
- pillow>=9.0.0
|
|
8
|
+
- openpyxl>=3.1.0
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# PPTX 文件生成器
|
|
12
|
+
|
|
13
|
+
## 任务目标
|
|
14
|
+
- 本 Skill 用于:将 JSON 格式的 PPT 内容转换为标准的 .pptx 文件
|
|
15
|
+
- 能力包含:JSON 解析、PPTX 创建、多布局支持、样式应用、图表生成、表格生成
|
|
16
|
+
- 触发条件:用户需要生成 .pptx 文件,或需要将 JSON 数据转换为可编辑的 PPT
|
|
17
|
+
|
|
18
|
+
## 前置准备
|
|
19
|
+
- 依赖说明:scripts 脚本所需的依赖包
|
|
20
|
+
```
|
|
21
|
+
python-pptx>=1.0.2
|
|
22
|
+
pillow>=9.0.0
|
|
23
|
+
openpyxl>=3.1.0
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 操作步骤
|
|
27
|
+
|
|
28
|
+
### 标准流程(JSON 转 PPTX)
|
|
29
|
+
|
|
30
|
+
#### 步骤 1:接收 JSON 数据
|
|
31
|
+
从以下来源接收 JSON 数据:
|
|
32
|
+
- **ppt-generator Skill**:7 角色协作生成的 JSON
|
|
33
|
+
- **用户直接提供**:符合格式规范的 JSON 文件
|
|
34
|
+
- **其他来源**:任何符合 JSON 格式的 PPT 数据
|
|
35
|
+
|
|
36
|
+
#### 步骤 2:验证 JSON 格式
|
|
37
|
+
调用 `scripts/json_validator.py` 验证 JSON 格式:
|
|
38
|
+
```bash
|
|
39
|
+
python scripts/json_validator.py --input ./ppt_data.json
|
|
40
|
+
```
|
|
41
|
+
验证内容包括:
|
|
42
|
+
- 元数据完整性(title, author, theme)
|
|
43
|
+
- 幻灯片数组存在性
|
|
44
|
+
- 每个幻灯片的必需字段(title, content)
|
|
45
|
+
- 数据类型正确性
|
|
46
|
+
|
|
47
|
+
#### 步骤 3:生成 PPTX 文件
|
|
48
|
+
调用 `scripts/pptx_builder.py` 生成 .pptx 文件:
|
|
49
|
+
```bash
|
|
50
|
+
python scripts/pptx_builder.py \
|
|
51
|
+
--input ./ppt_data.json \
|
|
52
|
+
--style assets/styles/modern.json \
|
|
53
|
+
--output ./presentation.pptx
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**核心功能**:
|
|
57
|
+
1. **创建演示文稿**:初始化 Presentation 对象
|
|
58
|
+
2. **添加幻灯片**:根据 JSON 数据逐页添加
|
|
59
|
+
3. **应用布局**:根据幻灯片类型选择布局
|
|
60
|
+
4. **添加内容**:
|
|
61
|
+
- 标题(Title)
|
|
62
|
+
- 内容(Text、Bullet Points)
|
|
63
|
+
- 图片(Picture)
|
|
64
|
+
- 图表(Chart)
|
|
65
|
+
- 表格(Table)
|
|
66
|
+
5. **应用样式**:根据风格配置设置字体、颜色、间距
|
|
67
|
+
6. **保存文件**:导出为 .pptx 文件
|
|
68
|
+
|
|
69
|
+
#### 步骤 4:验证 PPTX 文件
|
|
70
|
+
调用 `scripts/pptx_validator.py` 验证生成的 .pptx 文件:
|
|
71
|
+
```bash
|
|
72
|
+
python scripts/pptx_validator.py --input ./presentation.pptx
|
|
73
|
+
```
|
|
74
|
+
验证内容包括:
|
|
75
|
+
- 文件完整性
|
|
76
|
+
- 幻灯片数量
|
|
77
|
+
- 内容正确性
|
|
78
|
+
- 可编辑性
|
|
79
|
+
|
|
80
|
+
### 高级功能
|
|
81
|
+
|
|
82
|
+
#### 自定义样式
|
|
83
|
+
使用自定义风格配置:
|
|
84
|
+
```bash
|
|
85
|
+
python scripts/pptx_builder.py \
|
|
86
|
+
--input ./ppt_data.json \
|
|
87
|
+
--style ./custom_style.json \
|
|
88
|
+
--output ./presentation.pptx
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### 批量生成
|
|
92
|
+
批量处理多个 JSON 文件:
|
|
93
|
+
```bash
|
|
94
|
+
python scripts/pptx_builder.py \
|
|
95
|
+
--input-dir ./json_files/ \
|
|
96
|
+
--style assets/styles/modern.json \
|
|
97
|
+
--output-dir ./pptx_files/
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### 使用模板
|
|
101
|
+
基于模板生成 PPTX:
|
|
102
|
+
```bash
|
|
103
|
+
python scripts/pptx_builder.py \
|
|
104
|
+
--input ./ppt_data.json \
|
|
105
|
+
--template assets/templates/business_template.pptx \
|
|
106
|
+
--output ./presentation.pptx
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 与其他 Skill 协同
|
|
110
|
+
|
|
111
|
+
#### 与 ppt-generator 协同
|
|
112
|
+
```
|
|
113
|
+
用户请求:"生成一个 PPT 文件"
|
|
114
|
+
|
|
115
|
+
┌─────────────────────────────────────────────────────────┐
|
|
116
|
+
│ ppt-generator Skill │
|
|
117
|
+
├─────────────────────────────────────────────────────────┤
|
|
118
|
+
│ 1. 主题分析师:分析主题 │
|
|
119
|
+
│ 2. 模板设计师:推荐布局 │
|
|
120
|
+
│ 3. 内容策划师:规划内容结构 │
|
|
121
|
+
│ 4. 文本创作者:撰写内容 │
|
|
122
|
+
│ 5. 视觉设计师:提供配图建议 │
|
|
123
|
+
│ 6. 优化编辑师:优化文本 │
|
|
124
|
+
│ 7. PPT 构建师:生成 JSON 数据 │
|
|
125
|
+
└─────────────────────────────────────────────────────────┘
|
|
126
|
+
│
|
|
127
|
+
▼ ppt_data.json
|
|
128
|
+
┌─────────────────────────────────────────────────────────┐
|
|
129
|
+
│ pptx-generator Skill │
|
|
130
|
+
├─────────────────────────────────────────────────────────┤
|
|
131
|
+
│ 1. JSON 验证(json_validator.py) │
|
|
132
|
+
│ 2. PPTX 构建(pptx_builder.py) │
|
|
133
|
+
│ - 创建演示文稿 │
|
|
134
|
+
│ - 添加幻灯片 │
|
|
135
|
+
│ - 应用布局和样式 │
|
|
136
|
+
│ - 添加内容(文本、图片、图表、表格) │
|
|
137
|
+
│ 3. PPTX 验证(pptx_validator.py) │
|
|
138
|
+
│ 4. 输出 .pptx 文件 │
|
|
139
|
+
└─────────────────────────────────────────────────────────┘
|
|
140
|
+
│
|
|
141
|
+
▼ presentation.pptx
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### 与 nanobanana-ppt-visualizer 协同
|
|
145
|
+
```
|
|
146
|
+
用户请求:"生成 PPT 文件和图片"
|
|
147
|
+
|
|
148
|
+
ppt-generator → pptx-generator → nanobanana-ppt-visualizer
|
|
149
|
+
↓ ↓ ↓
|
|
150
|
+
JSON 数据 .pptx 文件 图片 + HTML 播放器
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### 完整工作流
|
|
154
|
+
```
|
|
155
|
+
1. ppt-generator → JSON 数据
|
|
156
|
+
2. pptx-generator → .pptx 文件
|
|
157
|
+
3. nanobanana-ppt-visualizer → 图片 + HTML 播放器
|
|
158
|
+
4. ppt-roadshow-generator → 视频
|
|
159
|
+
5. remotion-video-enhancer → 增强动画
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## 资源索引
|
|
163
|
+
- JSON 验证脚本:见 [scripts/json_validator.py](scripts/json_validator.py)(用途:验证 JSON 格式)
|
|
164
|
+
- PPTX 构建脚本:见 [scripts/pptx_builder.py](scripts/pptx_builder.py)(用途:生成 .pptx 文件)
|
|
165
|
+
- PPTX 验证脚本:见 [scripts/pptx_validator.py](scripts/pptx_validator.py)(用途:验证 .pptx 文件)
|
|
166
|
+
- 格式规范:见 [references/json_format_spec.md](references/json_format_spec.md)(用途:JSON 格式标准)
|
|
167
|
+
- 布局指南:见 [references/layout_guide.md](references/layout_guide.md)(用途:布局类型说明)
|
|
168
|
+
- 风格配置:见 [assets/styles/](assets/styles/)(可选:modern, minimal, business)
|
|
169
|
+
- 协同指南:见 [references/collaboration_guide.md](references/collaboration_guide.md)(用途:与其他 Skill 协同)
|
|
170
|
+
|
|
171
|
+
## 注意事项
|
|
172
|
+
- 本 Skill 使用 python-pptx 库生成标准的 .pptx 文件
|
|
173
|
+
- JSON 格式必须符合规范(见 references/json_format_spec.md)
|
|
174
|
+
- 支持的图片格式:PNG、JPG、JPEG、GIF
|
|
175
|
+
- 支持的图表类型:柱状图、折线图、饼图
|
|
176
|
+
- 支持的表格:普通表格、样式化表格
|
|
177
|
+
- 与 ppt-generator Skill 完全兼容,可无缝协同
|
|
178
|
+
- 生成的 .pptx 文件可在 Microsoft PowerPoint、WPS 等软件中编辑
|
|
179
|
+
|
|
180
|
+
## 使用示例
|
|
181
|
+
|
|
182
|
+
### 示例 1:与 ppt-generator 协同生成 PPTX
|
|
183
|
+
- 功能说明:ppt-generator 生成 JSON,pptx-generator 生成 .pptx
|
|
184
|
+
- 执行方式:ppt-generator → pptx-generator
|
|
185
|
+
- 用户指令:"生成一个产品介绍的 PPT 文件"
|
|
186
|
+
- 输出:presentation.pptx
|
|
187
|
+
|
|
188
|
+
### 示例 2:仅生成 PPTX 文件
|
|
189
|
+
- 功能说明:基于现有 JSON 生成 .pptx 文件
|
|
190
|
+
- 执行方式:pptx-generator 独立运行
|
|
191
|
+
- 关键参数:JSON 文件路径、风格配置
|
|
192
|
+
- 命令:`python scripts/pptx_builder.py --input ./ppt_data.json --output ./presentation.pptx`
|
|
193
|
+
|
|
194
|
+
### 示例 3:自定义风格生成
|
|
195
|
+
- 功能说明:使用自定义风格配置
|
|
196
|
+
- 执行方式:指定自定义风格文件
|
|
197
|
+
- 关键参数:--style
|
|
198
|
+
- 命令:`python scripts/pptx_builder.py --input ./ppt_data.json --style ./my_style.json --output ./presentation.pptx`
|
|
199
|
+
|
|
200
|
+
### 示例 4:批量生成 PPTX 文件
|
|
201
|
+
- 功能说明:一次性处理多个 JSON 文件
|
|
202
|
+
- 执行方式:批量处理
|
|
203
|
+
- 关键参数:--input-dir, --output-dir
|
|
204
|
+
- 命令:`python scripts/pptx_builder.py --input-dir ./json_files/ --output-dir ./pptx_files/`
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"metadata": {
|
|
3
|
+
"title": "演示文稿",
|
|
4
|
+
"author": "作者姓名",
|
|
5
|
+
"theme": "主题风格"
|
|
6
|
+
},
|
|
7
|
+
"slides": [
|
|
8
|
+
{
|
|
9
|
+
"layout": "TitleSlide",
|
|
10
|
+
"title": "幻灯片标题",
|
|
11
|
+
"content": [
|
|
12
|
+
"内容要点1",
|
|
13
|
+
"内容要点2",
|
|
14
|
+
"内容要点3"
|
|
15
|
+
],
|
|
16
|
+
"notes": "备注内容"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"layout": "ContentSlide",
|
|
20
|
+
"title": "核心内容",
|
|
21
|
+
"content": [
|
|
22
|
+
"要点1",
|
|
23
|
+
"要点2",
|
|
24
|
+
"要点3",
|
|
25
|
+
"要点4"
|
|
26
|
+
],
|
|
27
|
+
"notes": "详细说明"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"layout": "SummarySlide",
|
|
31
|
+
"title": "总结",
|
|
32
|
+
"content": [
|
|
33
|
+
"总结要点1",
|
|
34
|
+
"总结要点2",
|
|
35
|
+
"总结要点3"
|
|
36
|
+
],
|
|
37
|
+
"notes": "总结发言"
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|