zcode-app-cli 3.3.5-1

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.
Files changed (169) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +642 -0
  3. package/bin/zcode.js +848 -0
  4. package/config.example.json +110 -0
  5. package/package.json +81 -0
  6. package/vendor/.node-bundle-meta.json +6 -0
  7. package/vendor/extraction.json +11 -0
  8. package/vendor/node_modules/@zcode/tui/dist/index.js +161875 -0
  9. package/vendor/node_modules/@zcode/tui/package.json +14 -0
  10. package/vendor/packages/android-emulator-plugin/.mcp.json +19 -0
  11. package/vendor/packages/android-emulator-plugin/.zcode-plugin/plugin.json +63 -0
  12. package/vendor/packages/android-emulator-plugin/README.md +134 -0
  13. package/vendor/packages/android-emulator-plugin/commands/android-dev.md +11 -0
  14. package/vendor/packages/android-emulator-plugin/dist/lib/path.d.ts +4 -0
  15. package/vendor/packages/android-emulator-plugin/dist/lib/path.js +17 -0
  16. package/vendor/packages/android-emulator-plugin/dist/lib/result.d.ts +5 -0
  17. package/vendor/packages/android-emulator-plugin/dist/lib/result.js +22 -0
  18. package/vendor/packages/android-emulator-plugin/dist/lib/run.d.ts +18 -0
  19. package/vendor/packages/android-emulator-plugin/dist/lib/run.js +99 -0
  20. package/vendor/packages/android-emulator-plugin/dist/mcp/server.d.ts +3 -0
  21. package/vendor/packages/android-emulator-plugin/dist/mcp/server.js +47607 -0
  22. package/vendor/packages/android-emulator-plugin/dist/providers/app.d.ts +39 -0
  23. package/vendor/packages/android-emulator-plugin/dist/providers/app.js +50 -0
  24. package/vendor/packages/android-emulator-plugin/dist/providers/avd.d.ts +37 -0
  25. package/vendor/packages/android-emulator-plugin/dist/providers/avd.js +185 -0
  26. package/vendor/packages/android-emulator-plugin/dist/providers/build.d.ts +68 -0
  27. package/vendor/packages/android-emulator-plugin/dist/providers/build.js +131 -0
  28. package/vendor/packages/android-emulator-plugin/dist/providers/config.d.ts +7 -0
  29. package/vendor/packages/android-emulator-plugin/dist/providers/config.js +29 -0
  30. package/vendor/packages/android-emulator-plugin/dist/providers/device.d.ts +20 -0
  31. package/vendor/packages/android-emulator-plugin/dist/providers/device.js +91 -0
  32. package/vendor/packages/android-emulator-plugin/dist/providers/logs.d.ts +15 -0
  33. package/vendor/packages/android-emulator-plugin/dist/providers/logs.js +31 -0
  34. package/vendor/packages/android-emulator-plugin/dist/providers/preflight.d.ts +15 -0
  35. package/vendor/packages/android-emulator-plugin/dist/providers/preflight.js +123 -0
  36. package/vendor/packages/android-emulator-plugin/dist/providers/project-template.d.ts +13 -0
  37. package/vendor/packages/android-emulator-plugin/dist/providers/project-template.js +211 -0
  38. package/vendor/packages/android-emulator-plugin/dist/providers/project.d.ts +33 -0
  39. package/vendor/packages/android-emulator-plugin/dist/providers/project.js +195 -0
  40. package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.d.ts +14 -0
  41. package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.js +73 -0
  42. package/vendor/packages/android-emulator-plugin/dist/providers/sdk.d.ts +14 -0
  43. package/vendor/packages/android-emulator-plugin/dist/providers/sdk.js +185 -0
  44. package/vendor/packages/android-emulator-plugin/dist/providers/ui.d.ts +92 -0
  45. package/vendor/packages/android-emulator-plugin/dist/providers/ui.js +146 -0
  46. package/vendor/packages/android-emulator-plugin/hooks/hooks.json +3 -0
  47. package/vendor/packages/android-emulator-plugin/package.json +35 -0
  48. package/vendor/packages/android-emulator-plugin/skills/android-dev/INSTALL_ENVIRONMENT.md +357 -0
  49. package/vendor/packages/android-emulator-plugin/skills/android-dev/SKILL.md +73 -0
  50. package/vendor/packages/android-emulator-plugin/templates/compose-app/README.md +5 -0
  51. package/vendor/packages/document-skills-plugin/.zcode-plugin/plugin.json +8 -0
  52. package/vendor/packages/document-skills-plugin/package.json +8 -0
  53. package/vendor/packages/document-skills-plugin/skills/docx/LICENSE.txt +13 -0
  54. package/vendor/packages/document-skills-plugin/skills/docx/SKILL.md +201 -0
  55. package/vendor/packages/document-skills-plugin/skills/docx/references/chart-templates.md +386 -0
  56. package/vendor/packages/document-skills-plugin/skills/docx/references/common-rules.md +419 -0
  57. package/vendor/packages/document-skills-plugin/skills/docx/references/decorations.md +537 -0
  58. package/vendor/packages/document-skills-plugin/skills/docx/references/design-system.md +1797 -0
  59. package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-advanced.md +257 -0
  60. package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-core.md +332 -0
  61. package/vendor/packages/document-skills-plugin/skills/docx/references/faq.md +323 -0
  62. package/vendor/packages/document-skills-plugin/skills/docx/references/math-formulas.md +276 -0
  63. package/vendor/packages/document-skills-plugin/skills/docx/references/ooxml.md +222 -0
  64. package/vendor/packages/document-skills-plugin/skills/docx/references/toc.md +264 -0
  65. package/vendor/packages/document-skills-plugin/skills/docx/routes/comment.md +88 -0
  66. package/vendor/packages/document-skills-plugin/skills/docx/routes/create.md +207 -0
  67. package/vendor/packages/document-skills-plugin/skills/docx/routes/edit.md +115 -0
  68. package/vendor/packages/document-skills-plugin/skills/docx/routes/format.md +120 -0
  69. package/vendor/packages/document-skills-plugin/skills/docx/routes/read.md +114 -0
  70. package/vendor/packages/document-skills-plugin/skills/docx/scenes/academic.md +783 -0
  71. package/vendor/packages/document-skills-plugin/skills/docx/scenes/contract.md +463 -0
  72. package/vendor/packages/document-skills-plugin/skills/docx/scenes/copywriting.md +139 -0
  73. package/vendor/packages/document-skills-plugin/skills/docx/scenes/exam.md +698 -0
  74. package/vendor/packages/document-skills-plugin/skills/docx/scenes/official-doc.md +411 -0
  75. package/vendor/packages/document-skills-plugin/skills/docx/scenes/report.md +340 -0
  76. package/vendor/packages/document-skills-plugin/skills/docx/scenes/resume.md +534 -0
  77. package/vendor/packages/document-skills-plugin/skills/docx/scripts/__init__.py +1 -0
  78. package/vendor/packages/document-skills-plugin/skills/docx/scripts/add_toc_placeholders.py +749 -0
  79. package/vendor/packages/document-skills-plugin/skills/docx/scripts/document.py +1333 -0
  80. package/vendor/packages/document-skills-plugin/skills/docx/scripts/postcheck.py +807 -0
  81. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/comments.xml +3 -0
  82. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtended.xml +3 -0
  83. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
  84. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsIds.xml +3 -0
  85. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/people.xml +3 -0
  86. package/vendor/packages/document-skills-plugin/skills/docx/scripts/utilities.py +374 -0
  87. package/vendor/packages/document-skills-plugin/skills/docx/setup.sh +177 -0
  88. package/vendor/packages/document-skills-plugin/skills/pdf/LICENSE.txt +13 -0
  89. package/vendor/packages/document-skills-plugin/skills/pdf/SKILL.md +919 -0
  90. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/academic.md +1058 -0
  91. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/creative.md +770 -0
  92. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/poster.md +702 -0
  93. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process-advanced.md +284 -0
  94. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process.md +319 -0
  95. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/report.md +1659 -0
  96. package/vendor/packages/document-skills-plugin/skills/pdf/configs/components.md +153 -0
  97. package/vendor/packages/document-skills-plugin/skills/pdf/configs/fonts.md +93 -0
  98. package/vendor/packages/document-skills-plugin/skills/pdf/configs/visual_framework.md +263 -0
  99. package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-academic.tex +130 -0
  100. package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-altacv.tex +190 -0
  101. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/cover_validate.js +367 -0
  102. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/design_engine.py +2816 -0
  103. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2pdf-next.js +754 -0
  104. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2poster.js +256 -0
  105. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf.py +2959 -0
  106. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf_qa.py +901 -0
  107. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/poster_validate.py +1337 -0
  108. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/setup.sh +269 -0
  109. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/toc_validate.py +2075 -0
  110. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/charts.md +320 -0
  111. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover-backgrounds.md +384 -0
  112. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover.md +1442 -0
  113. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/fill-engine.md +527 -0
  114. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/geometry.md +142 -0
  115. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/overflow.md +630 -0
  116. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/pagination.md +367 -0
  117. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/palette.md +217 -0
  118. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/typography.md +20 -0
  119. package/vendor/packages/ios-simulator-plugin/.mcp.json +15 -0
  120. package/vendor/packages/ios-simulator-plugin/.zcode-plugin/plugin.json +34 -0
  121. package/vendor/packages/ios-simulator-plugin/README.md +111 -0
  122. package/vendor/packages/ios-simulator-plugin/commands/ios-dev.md +11 -0
  123. package/vendor/packages/ios-simulator-plugin/dist/lib/path.d.ts +4 -0
  124. package/vendor/packages/ios-simulator-plugin/dist/lib/path.js +18 -0
  125. package/vendor/packages/ios-simulator-plugin/dist/lib/result.d.ts +5 -0
  126. package/vendor/packages/ios-simulator-plugin/dist/lib/result.js +20 -0
  127. package/vendor/packages/ios-simulator-plugin/dist/lib/run.d.ts +17 -0
  128. package/vendor/packages/ios-simulator-plugin/dist/lib/run.js +83 -0
  129. package/vendor/packages/ios-simulator-plugin/dist/mcp/server.d.ts +3 -0
  130. package/vendor/packages/ios-simulator-plugin/dist/mcp/server.js +46833 -0
  131. package/vendor/packages/ios-simulator-plugin/dist/providers/build.d.ts +112 -0
  132. package/vendor/packages/ios-simulator-plugin/dist/providers/build.js +99 -0
  133. package/vendor/packages/ios-simulator-plugin/dist/providers/logs.d.ts +21 -0
  134. package/vendor/packages/ios-simulator-plugin/dist/providers/logs.js +26 -0
  135. package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.d.ts +12 -0
  136. package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.js +62 -0
  137. package/vendor/packages/ios-simulator-plugin/dist/providers/project.d.ts +35 -0
  138. package/vendor/packages/ios-simulator-plugin/dist/providers/project.js +288 -0
  139. package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.d.ts +22 -0
  140. package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.js +30 -0
  141. package/vendor/packages/ios-simulator-plugin/dist/providers/sim.d.ts +60 -0
  142. package/vendor/packages/ios-simulator-plugin/dist/providers/sim.js +116 -0
  143. package/vendor/packages/ios-simulator-plugin/dist/providers/ui.d.ts +57 -0
  144. package/vendor/packages/ios-simulator-plugin/dist/providers/ui.js +67 -0
  145. package/vendor/packages/ios-simulator-plugin/hooks/hooks.json +3 -0
  146. package/vendor/packages/ios-simulator-plugin/package.json +35 -0
  147. package/vendor/packages/ios-simulator-plugin/skills/ios-dev/SKILL.md +45 -0
  148. package/vendor/packages/ios-simulator-plugin/templates/swiftui-app/README.md +5 -0
  149. package/vendor/packages/restore-legacy-sessions-plugin/.zcode-plugin/plugin.json +9 -0
  150. package/vendor/packages/restore-legacy-sessions-plugin/README.md +35 -0
  151. package/vendor/packages/restore-legacy-sessions-plugin/commands/restore-legacy-sessions.md +11 -0
  152. package/vendor/packages/restore-legacy-sessions-plugin/package.json +8 -0
  153. package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/SKILL.md +92 -0
  154. package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/restore-conversation.mjs +648 -0
  155. package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/scan-legacy-sessions.mjs +422 -0
  156. package/vendor/packages/skill-creator-plugin/.zcode-plugin/plugin.json +8 -0
  157. package/vendor/packages/skill-creator-plugin/package.json +8 -0
  158. package/vendor/packages/skill-creator-plugin/skills/skill-creator/SKILL.md +159 -0
  159. package/vendor/packages/zcode-guide-plugin/.zcode-plugin/plugin.json +8 -0
  160. package/vendor/packages/zcode-guide-plugin/README.md +22 -0
  161. package/vendor/packages/zcode-guide-plugin/package.json +8 -0
  162. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-commands/SKILL.md +66 -0
  163. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-hooks/SKILL.md +66 -0
  164. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-mcp/SKILL.md +97 -0
  165. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-plugins/SKILL.md +59 -0
  166. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-skills/SKILL.md +61 -0
  167. package/vendor/packages/zcode-guide-plugin/skills/zcode-configuration-guide/SKILL.md +99 -0
  168. package/vendor/zcode.cjs +2926 -0
  169. package/zcode-runtime.lock.json +8 -0
@@ -0,0 +1,901 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PDF Quality Assurance Checker
4
+ =============================
5
+ Automatically detects common typesetting issues in PDFs.
6
+
7
+ Usage: python3 pdf_qa.py <pdf_path>
8
+
9
+ Checks:
10
+ 1. Page size consistency across all pages
11
+ 2. Blank page detection
12
+ 3. CJK punctuation placement (line-start/end forbidden punctuation)
13
+ 4. Color analysis (informational only — counts and lists colors)
14
+ 5. Font embedding check (warns on non-embedded fonts)
15
+ 6. PDF metadata check (title/author/creator)
16
+ 7. Content overflow detection (text exceeding page boundaries)
17
+ 8. Content fill ratio per page (multi-page docs, warns if < 40%)
18
+ 9. Cover/poster full-bleed check (background extends to page edges)
19
+ 10. Margin symmetry check (left/right text margins)
20
+ 11. Table centering check (if detected)
21
+ 12. Formula overflow check (optional)
22
+ """
23
+
24
+ import sys
25
+ import os
26
+ import re
27
+ import json
28
+ from collections import Counter
29
+
30
+ try:
31
+ import pymupdf # PyMuPDF
32
+ except ImportError:
33
+ import fitz as pymupdf
34
+
35
+ # ============================================================
36
+ # Config
37
+ # ============================================================
38
+
39
+ # CJK punctuation forbidden at line start
40
+ LINE_START_FORBIDDEN = set(
41
+ "。、,;:!?)】〛〉」』"
42
+ "\u201c\u201d" # "" curly double quotes
43
+ "\u2026" # … ellipsis
44
+ "\u2014" # — em dash
45
+ "\uff5e" # ~ fullwidth tilde
46
+ "\u00b7" # · middle dot
47
+ )
48
+
49
+ # CJK punctuation forbidden at line end
50
+ LINE_END_FORBIDDEN = set(
51
+ "(【《〈「"
52
+ "\u2018\u2019" # '' curly single quotes
53
+ "\u201c" # " left curly double quote
54
+ )
55
+
56
+ # Minimum fill ratio for last page (DISABLED — caused false positives)
57
+ # LAST_PAGE_MIN_FILL = 0.40
58
+
59
+ # Maximum allowed color count — REMOVED (color count is now info-only)
60
+ # MAX_COLORS = 8
61
+
62
+ # ============================================================
63
+ # Checks
64
+ # ============================================================
65
+
66
+ class QAResult:
67
+ def __init__(self):
68
+ self.issues = [] # (severity, category, message)
69
+ self.passes = [] # passed checks
70
+ self.info = [] # informational
71
+
72
+ def error(self, cat, msg):
73
+ self.issues.append(('ERROR', cat, msg))
74
+
75
+ def warn(self, cat, msg):
76
+ self.issues.append(('WARN', cat, msg))
77
+
78
+ def ok(self, msg):
79
+ self.passes.append(msg)
80
+
81
+ def add_info(self, msg):
82
+ self.info.append(msg)
83
+
84
+
85
+ def check_last_page_fill(doc, result):
86
+ """Check content fill ratio of the last page"""
87
+ if len(doc) < 2:
88
+ result.ok("Single-page document, no last-page blank check needed")
89
+ return
90
+
91
+ last_page = doc[-1]
92
+ page_rect = last_page.rect
93
+ page_area = page_rect.width * page_rect.height
94
+
95
+ # Get bounding boxes of all content on last page
96
+ blocks = last_page.get_text("blocks")
97
+ if not blocks:
98
+ result.error("Last page blank", f"Page {len(doc)} (last page) has no content at all!")
99
+ return
100
+
101
+ # Calculate max y-coordinate covered by content
102
+ max_y = 0
103
+ min_y = page_rect.height
104
+ for b in blocks:
105
+ if b[4].strip(): # Has text content
106
+ min_y = min(min_y, b[1])
107
+ max_y = max(max_y, b[3])
108
+
109
+ if max_y == 0:
110
+ result.error("Last page blank", f"Page {len(doc)} (last page) has no valid text content")
111
+ return
112
+
113
+ content_height = max_y - min_y
114
+ fill_ratio = content_height / page_rect.height
115
+
116
+ result.add_info(f"Last page fill ratio: {fill_ratio:.0%} (content height {content_height:.0f}px / page height {page_rect.height:.0f}px)")
117
+
118
+ if fill_ratio < 0.25:
119
+ result.error("Last page blank", f"Last page fill ratio only {fill_ratio:.0%}, mostly blank! Consider compressing preceding page spacing or trimming content")
120
+ elif fill_ratio < LAST_PAGE_MIN_FILL:
121
+ result.warn("Last page blank", f"Last page fill ratio {fill_ratio:.0%}, somewhat sparse — optimization recommended")
122
+ else:
123
+ result.ok(f"Last page fill ratio {fill_ratio:.0%} ✓")
124
+
125
+
126
+ def check_punctuation(doc, result):
127
+ """Check CJK punctuation placement rules"""
128
+ violations = []
129
+
130
+ for page_num in range(len(doc)):
131
+ page = doc[page_num]
132
+ # Extract text by line
133
+ text_dict = page.get_text("dict")
134
+
135
+ for block in text_dict.get("blocks", []):
136
+ if block.get("type") != 0: # Only check text blocks
137
+ continue
138
+ for line in block.get("lines", []):
139
+ line_text = ""
140
+ for span in line.get("spans", []):
141
+ line_text += span.get("text", "")
142
+
143
+ line_text = line_text.strip()
144
+ if not line_text:
145
+ continue
146
+
147
+ # Check line start
148
+ first_char = line_text[0]
149
+ if first_char in LINE_START_FORBIDDEN:
150
+ violations.append((page_num + 1, f"Forbidden line-start punctuation '{first_char}': ...{line_text[:30]}"))
151
+
152
+ # Check line end
153
+ last_char = line_text[-1] if len(line_text) > 0 else ''
154
+ if last_char in LINE_END_FORBIDDEN:
155
+ violations.append((page_num + 1, f"Forbidden line-end punctuation '{last_char}': {line_text[-30:]}..."))
156
+
157
+ if violations:
158
+ # Show at most 10
159
+ shown = violations[:10]
160
+ for page_num, desc in shown:
161
+ result.warn("Punctuation rules", f"Page {page_num} - {desc}")
162
+ if len(violations) > 10:
163
+ result.warn("Punctuation rules", f"...{len(violations) - 10} more violations")
164
+ else:
165
+ result.ok("Punctuation placement check passed ✓")
166
+
167
+
168
+ def check_blank_pages(doc, result):
169
+ """Check for completely blank pages"""
170
+ blank_pages = []
171
+ for i in range(len(doc)):
172
+ page = doc[i]
173
+ text = page.get_text().strip()
174
+ # Also check for images
175
+ images = page.get_images()
176
+ drawings = page.get_drawings()
177
+
178
+ if not text and not images and not drawings:
179
+ blank_pages.append(i + 1)
180
+
181
+ if blank_pages:
182
+ result.error("Blank pages", f"Found blank pages: {blank_pages}")
183
+ else:
184
+ result.ok("No blank pages ✓")
185
+
186
+
187
+ def check_colors(doc, result):
188
+ """Analyze colors used in the document (informational only, no pass/fail)"""
189
+ colors = set()
190
+
191
+ for page_num in range(len(doc)):
192
+ page = doc[page_num]
193
+ text_dict = page.get_text("dict")
194
+
195
+ for block in text_dict.get("blocks", []):
196
+ if block.get("type") != 0:
197
+ continue
198
+ for line in block.get("lines", []):
199
+ for span in line.get("spans", []):
200
+ color = span.get("color", 0)
201
+ if color != 0: # Exclude pure black
202
+ r = (color >> 16) & 0xFF
203
+ g = (color >> 8) & 0xFF
204
+ b = color & 0xFF
205
+ hex_color = f"#{r:02x}{g:02x}{b:02x}"
206
+ colors.add(hex_color)
207
+
208
+ # Check drawing colors
209
+ drawings = page.get_drawings()
210
+ for d in drawings:
211
+ if d.get("color"):
212
+ c = d["color"]
213
+ if isinstance(c, (tuple, list)) and len(c) >= 3:
214
+ hex_color = f"#{int(c[0]*255):02x}{int(c[1]*255):02x}{int(c[2]*255):02x}"
215
+ colors.add(hex_color)
216
+ if d.get("fill"):
217
+ c = d["fill"]
218
+ if isinstance(c, (tuple, list)) and len(c) >= 3:
219
+ hex_color = f"#{int(c[0]*255):02x}{int(c[1]*255):02x}{int(c[2]*255):02x}"
220
+ colors.add(hex_color)
221
+
222
+ # Filter out near-black/white/gray colors
223
+ distinct_colors = []
224
+ for c in colors:
225
+ r = int(c[1:3], 16)
226
+ g = int(c[3:5], 16)
227
+ b = int(c[5:7], 16)
228
+ max_diff = max(abs(r-g), abs(g-b), abs(r-b))
229
+ if max_diff > 20:
230
+ distinct_colors.append(c)
231
+
232
+ result.add_info(f"Total text colors: {len(colors)} (chromatic: {len(distinct_colors)})")
233
+
234
+ if distinct_colors:
235
+ result.add_info(f"Chromatic colors: {', '.join(sorted(distinct_colors)[:10])}")
236
+
237
+
238
+ def check_page_size_consistency(doc, result):
239
+ """Check whether all page sizes are consistent"""
240
+ if len(doc) < 2:
241
+ result.ok("Single-page document, size consistent ✓")
242
+ return
243
+
244
+ sizes = set()
245
+ for i in range(len(doc)):
246
+ page = doc[i]
247
+ w = round(page.rect.width, 1)
248
+ h = round(page.rect.height, 1)
249
+ sizes.add((w, h))
250
+
251
+ if len(sizes) > 1:
252
+ result.warn("Page size", f"Inconsistent page sizes: {sizes}")
253
+ else:
254
+ size = list(sizes)[0]
255
+ # Convert to mm
256
+ w_mm = size[0] * 25.4 / 72
257
+ h_mm = size[1] * 25.4 / 72
258
+ result.add_info(f"Page size: {w_mm:.0f}mm × {h_mm:.0f}mm ({len(doc)} pages)")
259
+ result.ok("Page size consistent ✓")
260
+
261
+
262
+ def check_text_overflow(doc, result):
263
+ """Check whether text overflows page boundaries"""
264
+ overflow_pages = []
265
+
266
+ for i in range(len(doc)):
267
+ page = doc[i]
268
+ rect = page.rect
269
+ blocks = page.get_text("blocks")
270
+
271
+ for b in blocks:
272
+ # b = (x0, y0, x1, y1, text, block_no, block_type)
273
+ if b[2] > rect.width + 2 or b[3] > rect.height + 2: # 2px tolerance
274
+ overflow_pages.append(i + 1)
275
+ break
276
+ if b[0] < -2 or b[1] < -2:
277
+ overflow_pages.append(i + 1)
278
+ break
279
+
280
+ if overflow_pages:
281
+ result.warn("Content overflow", f"Pages {overflow_pages} may have content exceeding page boundaries")
282
+ else:
283
+ result.ok("No content overflow ✓")
284
+
285
+
286
+ def check_content_fill_ratio(doc, result):
287
+ """Check content fill ratio per page — warns when content is crammed at top leaving large void below.
288
+
289
+ Rules:
290
+ - Skip single-page documents (may be intentional design)
291
+ - Skip page 1 (usually cover with intentional whitespace)
292
+ - Middle pages: warn if fill ratio < 40%
293
+ - Last page: warn if fill ratio < 25% (naturally has less content)
294
+ """
295
+ if len(doc) < 2:
296
+ result.ok("Single-page document, skipping content fill ratio check ✓")
297
+ return
298
+
299
+ low_fill_pages = []
300
+
301
+ for i in range(len(doc)):
302
+ page = doc[i]
303
+ page_rect = page.rect
304
+ page_height = page_rect.height
305
+
306
+ # Skip page 1 (cover)
307
+ if i == 0:
308
+ continue
309
+
310
+ blocks = page.get_text("blocks")
311
+ images = page.get_images()
312
+ drawings = page.get_drawings()
313
+
314
+ if not blocks and not images and not drawings:
315
+ continue # Blank page check handles this
316
+
317
+ # Calculate content bbox
318
+ max_y = 0
319
+ for b in blocks:
320
+ if b[4].strip():
321
+ max_y = max(max_y, b[3])
322
+
323
+ # Include images in bbox
324
+ for img in images:
325
+ try:
326
+ img_rects = page.get_image_rects(img[0])
327
+ for r in img_rects:
328
+ max_y = max(max_y, r.y1)
329
+ except Exception:
330
+ pass
331
+
332
+ if max_y == 0:
333
+ continue
334
+
335
+ fill_ratio = max_y / page_height
336
+ is_last = (i == len(doc) - 1)
337
+ threshold = 0.25 if is_last else 0.40
338
+
339
+ if fill_ratio < threshold:
340
+ low_fill_pages.append((i + 1, fill_ratio, threshold))
341
+
342
+ if low_fill_pages:
343
+ for pg, ratio, thresh in low_fill_pages:
344
+ result.warn(
345
+ "Content fill ratio",
346
+ f"Page {pg} content only fills {ratio:.0%} of page height "
347
+ f"(threshold: {thresh:.0%}). Content may be crammed at the top "
348
+ f"with a large blank area below."
349
+ )
350
+ else:
351
+ result.ok("Content fill ratio adequate on all pages ✓")
352
+
353
+
354
+ def check_cover_bleed(doc, result, poster=False):
355
+ """Check if the cover page (page 1) fills the entire page area (full-bleed).
356
+
357
+ A properly designed cover should have background color/graphics extending
358
+ to the page edges. If the content bbox has significant margins on all sides,
359
+ the cover likely wasn't rendered full-bleed (e.g. ReportLab with default margins).
360
+
361
+ For poster mode: checks ALL pages (not just the cover) since every page of a
362
+ seamlessly-paginated poster should have consistent background fill.
363
+
364
+ Strategy: combine bounding boxes of drawings (rects, paths), images, and colored
365
+ backgrounds. If the union bbox leaves > 5% margin on any side, warn.
366
+ """
367
+ if not poster and len(doc) < 2:
368
+ # Single page doc (non-poster) — not necessarily a cover scenario
369
+ return
370
+
371
+ pages_to_check = range(len(doc)) if poster else [0]
372
+
373
+ for page_idx in pages_to_check:
374
+ page = doc[page_idx]
375
+ page_rect = page.rect
376
+ pw, ph = page_rect.width, page_rect.height
377
+
378
+ # Collect all content bounding boxes
379
+ min_x, min_y = pw, ph
380
+ max_x, max_y = 0.0, 0.0
381
+ has_content = False
382
+
383
+ # 1. Drawings (vector paths, rectangles — typical for colored backgrounds)
384
+ for d in page.get_drawings():
385
+ r = d.get("rect")
386
+ if r:
387
+ min_x = min(min_x, r.x0)
388
+ min_y = min(min_y, r.y0)
389
+ max_x = max(max_x, r.x1)
390
+ max_y = max(max_y, r.y1)
391
+ has_content = True
392
+
393
+ # 2. Images
394
+ for img in page.get_images():
395
+ try:
396
+ for r in page.get_image_rects(img[0]):
397
+ min_x = min(min_x, r.x0)
398
+ min_y = min(min_y, r.y0)
399
+ max_x = max(max_x, r.x1)
400
+ max_y = max(max_y, r.y1)
401
+ has_content = True
402
+ except Exception:
403
+ pass
404
+
405
+ page_label = f"Page {page_idx + 1}" if poster else "Cover page (p1)"
406
+
407
+ if not has_content:
408
+ blocks = page.get_text("blocks")
409
+ if blocks:
410
+ result.warn(
411
+ f"{page_label} not full-bleed",
412
+ f"{page_label} has no background graphics (no filled rectangles or images). "
413
+ "A proper cover/poster page should have a full-page background color or image "
414
+ "extending to all edges."
415
+ )
416
+ continue
417
+
418
+ # Calculate margin ratios (how far content is from page edges)
419
+ margin_left = max(0, min_x) / pw
420
+ margin_top = max(0, min_y) / ph
421
+ margin_right = max(0, pw - max_x) / pw
422
+ margin_bottom = max(0, ph - max_y) / ph
423
+
424
+ threshold = 0.05
425
+ margins_ok = (margin_left <= threshold and margin_top <= threshold and
426
+ margin_right <= threshold and margin_bottom <= threshold)
427
+
428
+ if margins_ok:
429
+ result.ok(f"{page_label} content extends to page edges (full-bleed) ✓")
430
+ else:
431
+ sides = []
432
+ if margin_left > threshold:
433
+ sides.append(f"left {margin_left:.0%}")
434
+ if margin_top > threshold:
435
+ sides.append(f"top {margin_top:.0%}")
436
+ if margin_right > threshold:
437
+ sides.append(f"right {margin_right:.0%}")
438
+ if margin_bottom > threshold:
439
+ sides.append(f"bottom {margin_bottom:.0%}")
440
+ result.warn(
441
+ f"{page_label} not full-bleed",
442
+ f"{page_label} has visible margins: {', '.join(sides)}. "
443
+ f"Background/graphics should extend to page edges."
444
+ )
445
+
446
+
447
+ def check_margin_symmetry(doc, result, skip_cover=False):
448
+ """Check left/right margin symmetry using text block bounds."""
449
+ warn_pages = []
450
+
451
+ for page_num in range(len(doc)):
452
+ if skip_cover and page_num == 0:
453
+ continue
454
+
455
+ page = doc[page_num]
456
+ blocks = page.get_text("blocks")
457
+ text_blocks = [b for b in blocks if b[4].strip()]
458
+
459
+ if len(text_blocks) < 3:
460
+ continue # Skip decorative/cover-like pages
461
+
462
+ left_margin = min(b[0] for b in text_blocks)
463
+ right_margin = page.rect.width - max(b[2] for b in text_blocks)
464
+ diff = abs(left_margin - right_margin)
465
+
466
+ if diff > page.rect.width * 0.05:
467
+ warn_pages.append((page_num + 1, left_margin, right_margin, diff))
468
+
469
+ if warn_pages:
470
+ for pg, left, right, diff in warn_pages:
471
+ result.warn(
472
+ "Margin symmetry",
473
+ f"Page {pg} left/right margins differ by {diff:.0f}pt "
474
+ f"(L {left:.0f}pt, R {right:.0f}pt)"
475
+ )
476
+ else:
477
+ result.ok("Left/right margins appear symmetric \u2713")
478
+
479
+
480
+ def check_table_centering(doc, result):
481
+ """Check if detected table regions are centered."""
482
+ def _bbox_intersects(a, b, tol=6):
483
+ return not (a[2] < b[0] - tol or a[0] > b[2] + tol or
484
+ a[3] < b[1] - tol or a[1] > b[3] + tol)
485
+
486
+ def _rect_tuple(r):
487
+ if hasattr(r, "x0"):
488
+ return (r.x0, r.y0, r.x1, r.y1)
489
+ return (r[0], r[1], r[2], r[3])
490
+
491
+ any_tables = False
492
+
493
+ for page_num in range(len(doc)):
494
+ page = doc[page_num]
495
+ drawings = page.get_drawings()
496
+ segments = []
497
+
498
+ for d in drawings:
499
+ for item in d.get("items", []):
500
+ if not item:
501
+ continue
502
+ op = item[0]
503
+ if op == "l" and len(item) >= 3:
504
+ p0, p1 = item[1], item[2]
505
+ segments.append((p0[0], p0[1], p1[0], p1[1]))
506
+ elif op == "re" and len(item) >= 2:
507
+ x0, y0, x1, y1 = _rect_tuple(item[1])
508
+ segments.extend([
509
+ (x0, y0, x1, y0),
510
+ (x0, y1, x1, y1),
511
+ (x0, y0, x0, y1),
512
+ (x1, y0, x1, y1),
513
+ ])
514
+
515
+ if not segments:
516
+ continue
517
+
518
+ cluster_list = []
519
+ for x0, y0, x1, y1 in segments:
520
+ min_x, max_x = min(x0, x1), max(x0, x1)
521
+ min_y, max_y = min(y0, y1), max(y0, y1)
522
+ bbox = (min_x, min_y, max_x, max_y)
523
+ is_h = abs(y0 - y1) < 1 and (max_x - min_x) > 20
524
+ is_v = abs(x0 - x1) < 1 and (max_y - min_y) > 20
525
+ if not is_h and not is_v:
526
+ continue
527
+
528
+ placed = False
529
+ for cl in cluster_list:
530
+ if _bbox_intersects(bbox, cl["bbox"]):
531
+ cl["segments"].append((x0, y0, x1, y1, is_h, is_v))
532
+ cl["bbox"] = (
533
+ min(cl["bbox"][0], bbox[0]),
534
+ min(cl["bbox"][1], bbox[1]),
535
+ max(cl["bbox"][2], bbox[2]),
536
+ max(cl["bbox"][3], bbox[3]),
537
+ )
538
+ if is_h:
539
+ cl["h"] += 1
540
+ if is_v:
541
+ cl["v"] += 1
542
+ placed = True
543
+ break
544
+ if not placed:
545
+ cluster_list.append({
546
+ "bbox": bbox,
547
+ "segments": [(x0, y0, x1, y1, is_h, is_v)],
548
+ "h": 1 if is_h else 0,
549
+ "v": 1 if is_v else 0,
550
+ })
551
+
552
+ for cl in cluster_list:
553
+ if cl["h"] < 2 or cl["v"] < 2:
554
+ continue
555
+ any_tables = True
556
+ bbox = cl["bbox"]
557
+ page_width = page.rect.width
558
+ left_margin = bbox[0]
559
+ right_margin = page_width - bbox[2]
560
+ if abs(left_margin - right_margin) > page_width * 0.05:
561
+ result.warn(
562
+ "Table centering",
563
+ f"Page {page_num + 1}: Table not centered "
564
+ f"(L {left_margin:.0f}pt, R {right_margin:.0f}pt)"
565
+ )
566
+
567
+ if any_tables:
568
+ result.ok("Table centering check complete \u2713")
569
+
570
+
571
+ def check_font_embedding(doc, result):
572
+ """Check font embedding status using PyMuPDF font list."""
573
+ fonts_used = set()
574
+ non_embedded = set()
575
+
576
+ for page_num in range(len(doc)):
577
+ page = doc[page_num]
578
+ for font in page.get_fonts():
579
+ basefont = font[3] if len(font) > 3 else "unknown"
580
+ ext = font[1] if len(font) > 1 else ""
581
+ fonts_used.add(basefont)
582
+ if not ext:
583
+ non_embedded.add(basefont)
584
+
585
+ if fonts_used:
586
+ result.add_info(f"Fonts used: {', '.join(sorted(fonts_used))}")
587
+ else:
588
+ result.add_info("Fonts used: (none detected)")
589
+
590
+ if non_embedded:
591
+ for basefont in sorted(non_embedded):
592
+ result.warn(
593
+ "Font embedding",
594
+ f"Font {basefont} is not embedded. May display differently on other systems."
595
+ )
596
+ else:
597
+ result.ok("All fonts are embedded \u2713")
598
+
599
+
600
+ def check_helvetica_in_cjk(doc, result):
601
+ """Detect Helvetica rendering visible text in documents containing CJK text.
602
+
603
+ Helvetica is a Latin-only built-in PDF font. When it appears rendering
604
+ actual text content in a CJK document, it almost always means a raw string
605
+ was passed to a ReportLab Table or flowable without wrapping it in
606
+ Paragraph() with a CJK font. The CJK characters rendered via Helvetica
607
+ become garbled (fall back to ZapfDingbats symbols).
608
+
609
+ We only check Helvetica (not ZapfDingbats) because ZapfDingbats is
610
+ legitimately used for bullet symbols in list items.
611
+
612
+ We check actual rendered text spans (not just font presence in font list)
613
+ because ReportLab internally registers Helvetica on every page even when
614
+ only CJK fonts are used in visible content.
615
+ """
616
+ has_cjk = False
617
+ helvetica_pages = []
618
+
619
+ for page_num in range(len(doc)):
620
+ page = doc[page_num]
621
+ text = page.get_text("text") or ""
622
+
623
+ # Check if document contains CJK characters
624
+ if not has_cjk:
625
+ for ch in text:
626
+ if '\u4e00' <= ch <= '\u9fff' or '\u3400' <= ch <= '\u4dbf':
627
+ has_cjk = True
628
+ break
629
+
630
+ # Check if Helvetica is actually used to render visible text on this page
631
+ blocks = page.get_text("dict", sort=True).get("blocks", [])
632
+ found_on_page = False
633
+ for block in blocks:
634
+ if found_on_page:
635
+ break
636
+ for line in block.get("lines", []):
637
+ if found_on_page:
638
+ break
639
+ for span in line.get("spans", []):
640
+ font = span.get("font", "")
641
+ txt = span.get("text", "").strip()
642
+ if "Helvetica" in font and len(txt) > 0:
643
+ helvetica_pages.append(page_num + 1)
644
+ found_on_page = True
645
+ break
646
+
647
+ if has_cjk and helvetica_pages:
648
+ pages_str = ', '.join(str(p) for p in helvetica_pages[:5])
649
+ if len(helvetica_pages) > 5:
650
+ pages_str += f' ...and {len(helvetica_pages) - 5} more'
651
+ result.warn(
652
+ "Helvetica in CJK document",
653
+ f"Helvetica font detected rendering text on page(s) {pages_str} in a CJK document. "
654
+ f"This usually means a raw string was passed to a ReportLab Table or flowable "
655
+ f"without wrapping in Paragraph(text, style) with a CJK-capable font. "
656
+ f"CJK characters rendered via Helvetica will appear as garbled symbols."
657
+ )
658
+
659
+
660
+ def check_metadata(doc, result):
661
+ """Check PDF metadata presence for title, author, creator."""
662
+ meta = doc.metadata or {}
663
+
664
+ def _missing(v):
665
+ if v is None:
666
+ return True
667
+ if not str(v).strip():
668
+ return True
669
+ return False
670
+
671
+ title = meta.get("title")
672
+ author = meta.get("author")
673
+ creator = meta.get("creator")
674
+
675
+ if _missing(title) or str(title).strip().lower() in ("untitled", "(anonymous)"):
676
+ result.warn("Metadata", "Missing/invalid title metadata")
677
+ else:
678
+ result.ok("Title metadata present \u2713")
679
+
680
+ if _missing(author):
681
+ result.warn("Metadata", "Missing author metadata")
682
+ else:
683
+ result.ok("Author metadata present \u2713")
684
+
685
+ if _missing(creator):
686
+ result.warn("Metadata", "Missing creator metadata")
687
+ else:
688
+ result.ok("Creator metadata present \u2713")
689
+
690
+
691
+ def check_toc_without_cover(doc, result):
692
+ """Detect TOC on page 1 without a preceding cover page.
693
+
694
+ If the first page contains Table of Contents / 目录, it means the document
695
+ has a TOC but no cover page. This is a structural issue — documents with
696
+ TOC should have: Cover (p1) → TOC (p2) → Content (p3+).
697
+ """
698
+ if len(doc) < 2:
699
+ # Single-page docs don't need TOC/cover checks
700
+ return
701
+
702
+ page1 = doc[0]
703
+ text = page1.get_text("text", sort=True).strip()
704
+
705
+ # Normalize for matching
706
+ text_lower = text.lower()
707
+ first_300 = text_lower[:300]
708
+
709
+ toc_keywords = [
710
+ "table of contents", "contents",
711
+ "目录", "目 录",
712
+ ]
713
+
714
+ has_toc = any(kw in first_300 for kw in toc_keywords)
715
+
716
+ if has_toc:
717
+ result.warn(
718
+ "TOC without cover",
719
+ "Page 1 appears to be a Table of Contents with no preceding cover page. "
720
+ "Documents with TOC should have: Cover (p1) → TOC (p2) → Content (p3+)."
721
+ )
722
+
723
+
724
+ def check_formula_overflow(doc, result):
725
+ """Detect likely formula overflow past right content margin."""
726
+ math_re = re.compile(r"[=+\-*/<>\u2264\u2265\u2211\u222b\u221a\u03c0\u00b5\u221e\u2202\u2206\u2248\u2260\u00b1\u00d7\u00f7]")
727
+
728
+ for page_num in range(len(doc)):
729
+ page = doc[page_num]
730
+ blocks = page.get_text("blocks")
731
+ text_blocks = [b for b in blocks if b[4].strip()]
732
+
733
+ if len(text_blocks) < 3:
734
+ continue
735
+
736
+ right_edges = sorted(b[2] for b in text_blocks)
737
+ mid = len(right_edges) // 2
738
+ content_right = right_edges[mid] if right_edges else 0
739
+
740
+ for b in text_blocks:
741
+ x0, x1, text = b[0], b[2], b[4]
742
+ if x1 <= content_right + 10:
743
+ continue
744
+
745
+ is_single_line = "\n" not in text.strip()
746
+ is_wide = (x1 - x0) > page.rect.width * 0.5
747
+ has_math = bool(math_re.search(text))
748
+
749
+ if (is_single_line and is_wide) or has_math:
750
+ delta = x1 - content_right
751
+ result.warn(
752
+ "Formula overflow",
753
+ f"Page {page_num + 1}: Content extends {delta:.0f}pt beyond right content margin "
754
+ "(possible formula overflow)"
755
+ )
756
+ break
757
+
758
+
759
+ # ============================================================
760
+ # Main
761
+ # ============================================================
762
+
763
+ def run_qa(pdf_path, poster=False, skip_cover=False, check_tables=True, check_formulas=False):
764
+ result = QAResult()
765
+
766
+ if not os.path.exists(pdf_path):
767
+ result.error("File", f"File not found: {pdf_path}")
768
+ return result
769
+
770
+ doc = pymupdf.open(pdf_path)
771
+
772
+ result.add_info(f"File: {os.path.basename(pdf_path)}")
773
+ result.add_info(f"Size: {os.path.getsize(pdf_path) / 1024:.1f} KB")
774
+ if poster:
775
+ result.add_info("Mode: poster (creative)")
776
+
777
+ # Run all checks
778
+ check_metadata(doc, result)
779
+ check_page_size_consistency(doc, result)
780
+ check_blank_pages(doc, result)
781
+ check_punctuation(doc, result)
782
+ check_colors(doc, result)
783
+ check_font_embedding(doc, result)
784
+ check_helvetica_in_cjk(doc, result)
785
+ check_text_overflow(doc, result)
786
+ if not poster:
787
+ # Content fill ratio is not meaningful for posters — the last page
788
+ # of a seamlessly-paginated poster naturally has less content.
789
+ check_content_fill_ratio(doc, result)
790
+ check_cover_bleed(doc, result, poster=poster)
791
+ check_margin_symmetry(doc, result, skip_cover=skip_cover)
792
+ if check_tables:
793
+ check_table_centering(doc, result)
794
+ if check_formulas:
795
+ check_formula_overflow(doc, result)
796
+ if not poster:
797
+ check_toc_without_cover(doc, result)
798
+
799
+ doc.close()
800
+ return result
801
+
802
+
803
+ def format_report(result):
804
+ lines = []
805
+ lines.append("=" * 56)
806
+ lines.append(" PDF Quality Assurance Report")
807
+ lines.append("=" * 56)
808
+
809
+ # Info
810
+ if result.info:
811
+ lines.append("")
812
+ lines.append("ℹ️ Info:")
813
+ for msg in result.info:
814
+ lines.append(f" {msg}")
815
+
816
+ # Passes
817
+ if result.passes:
818
+ lines.append("")
819
+ lines.append(f"✅ Passed ({len(result.passes)}):")
820
+ for msg in result.passes:
821
+ lines.append(f" {msg}")
822
+
823
+ # Issues
824
+ errors = [(s, c, m) for s, c, m in result.issues if s == 'ERROR']
825
+ warns = [(s, c, m) for s, c, m in result.issues if s == 'WARN']
826
+
827
+ if errors:
828
+ lines.append("")
829
+ lines.append(f"❌ Errors ({len(errors)}):")
830
+ for _, cat, msg in errors:
831
+ lines.append(f" [{cat}] {msg}")
832
+
833
+ if warns:
834
+ lines.append("")
835
+ lines.append(f"⚠️ Warnings ({len(warns)}):")
836
+ for _, cat, msg in warns:
837
+ lines.append(f" [{cat}] {msg}")
838
+
839
+ # Summary
840
+ lines.append("")
841
+ lines.append("-" * 56)
842
+ total_issues = len(result.issues)
843
+ if total_issues == 0:
844
+ lines.append("🎉 PASS — All checks passed!")
845
+ elif errors:
846
+ lines.append(f"💀 FAIL — {len(errors)} error(s), {len(warns)} warning(s)")
847
+ else:
848
+ lines.append(f"⚠️ WARN — {len(warns)} warning(s), optimization recommended")
849
+ lines.append("-" * 56)
850
+
851
+ return "\n".join(lines)
852
+
853
+
854
+ if __name__ == "__main__":
855
+ if len(sys.argv) < 2:
856
+ print("Usage: python3 pdf_qa.py <pdf_path>")
857
+ print(" python3 pdf_qa.py *.pdf (batch check)")
858
+ print("Options:")
859
+ print(" --poster Poster mode (creative)")
860
+ print(" --skip-cover Skip page 1 margin symmetry check")
861
+ print(" --no-tables Disable table centering check")
862
+ print(" --formulas Enable formula overflow check")
863
+ sys.exit(1)
864
+
865
+ import glob
866
+ files = []
867
+ poster = False
868
+ skip_cover = False
869
+ check_tables = True
870
+ check_formulas = False
871
+ args = sys.argv[1:]
872
+ if '--poster' in args:
873
+ poster = True
874
+ args.remove('--poster')
875
+ if '--skip-cover' in args:
876
+ skip_cover = True
877
+ args.remove('--skip-cover')
878
+ if '--no-tables' in args:
879
+ check_tables = False
880
+ args.remove('--no-tables')
881
+ if '--formulas' in args:
882
+ check_formulas = True
883
+ args.remove('--formulas')
884
+ for arg in args:
885
+ files.extend(glob.glob(arg))
886
+
887
+ if not files:
888
+ print(f"File not found: {args}")
889
+ sys.exit(1)
890
+
891
+ for pdf_path in files:
892
+ result = run_qa(
893
+ pdf_path,
894
+ poster=poster,
895
+ skip_cover=skip_cover,
896
+ check_tables=check_tables,
897
+ check_formulas=check_formulas
898
+ )
899
+ print(format_report(result))
900
+ if len(files) > 1:
901
+ print("\n")