proof-pdf 0.3.4__tar.gz → 0.3.6__tar.gz

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 (96) hide show
  1. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/PKG-INFO +58 -2
  2. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/README.md +57 -1
  3. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/pyproject.toml +1 -1
  4. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/__init__.py +4 -2
  5. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/colour.py +52 -20
  6. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/content.py +4 -3
  7. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/contrast.py +3 -0
  8. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/fonts.py +64 -0
  9. proof_pdf-0.3.6/src/proof_pdf/_internal/functions.py +233 -0
  10. proof_pdf-0.3.6/src/proof_pdf/_internal/interactive.py +286 -0
  11. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/paint.py +225 -22
  12. proof_pdf-0.3.6/src/proof_pdf/_internal/previews.py +269 -0
  13. proof_pdf-0.3.6/src/proof_pdf/_internal/spots.py +55 -0
  14. proof_pdf-0.3.6/src/proof_pdf/_internal/tables.py +230 -0
  15. proof_pdf-0.3.6/src/proof_pdf/_internal/tagged.py +193 -0
  16. proof_pdf-0.3.6/src/proof_pdf/_internal/vector.py +675 -0
  17. proof_pdf-0.3.6/src/proof_pdf/_internal/xmp.py +76 -0
  18. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/cli.py +134 -1
  19. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/core.py +17 -7
  20. proof_pdf-0.3.6/src/proof_pdf/crop.py +56 -0
  21. proof_pdf-0.3.6/src/proof_pdf/extract.py +873 -0
  22. proof_pdf-0.3.6/src/proof_pdf/layout.py +625 -0
  23. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/models.py +11 -0
  24. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_colour.py +198 -0
  25. proof_pdf-0.3.6/tests/test_proof_pdf/test_crop.py +92 -0
  26. proof_pdf-0.3.6/tests/test_proof_pdf/test_extract.py +631 -0
  27. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_integration.py +6 -0
  28. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_public_api.py +1 -1
  29. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/LICENSE +0 -0
  30. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/NOTICE +0 -0
  31. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/__init__.py +0 -0
  32. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/config.py +0 -0
  33. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/deltae.py +0 -0
  34. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/proc.py +0 -0
  35. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/resolution.py +0 -0
  36. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/spaces.py +0 -0
  37. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/structure.py +0 -0
  38. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/text.py +0 -0
  39. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/_internal/verapdf.py +0 -0
  40. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/config.py +0 -0
  41. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/inventory.py +0 -0
  42. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/preview.py +0 -0
  43. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/py.typed +0 -0
  44. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/src/proof_pdf/texlog.py +0 -0
  45. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/build_pdfs.py +0 -0
  46. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/black-text.pdf +0 -0
  47. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/corrupt.pdf +0 -0
  48. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/cyan-text.pdf +0 -0
  49. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/edge-text.pdf +0 -0
  50. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/embedded-text.pdf +0 -0
  51. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/good.pdf +0 -0
  52. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/hairline.pdf +0 -0
  53. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/heavy-ink.pdf +0 -0
  54. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/high-contrast.pdf +0 -0
  55. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/low-contrast.pdf +0 -0
  56. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/low-dpi-image.pdf +0 -0
  57. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/no-bleed.pdf +0 -0
  58. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/no-output-intent.pdf +0 -0
  59. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/notdef-text.pdf +0 -0
  60. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/plain.pdf +0 -0
  61. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/registration-spot.pdf +0 -0
  62. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/rgb-image.pdf +0 -0
  63. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/rich-black-text.pdf +0 -0
  64. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/small-text.pdf +0 -0
  65. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/spot-ink.pdf +0 -0
  66. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/three-pages.pdf +0 -0
  67. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/transparent-matching.pdf +0 -0
  68. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/transparent-mismatch.pdf +0 -0
  69. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/transparent-undeclared.pdf +0 -0
  70. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/two-sizes.pdf +0 -0
  71. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/type3-text.pdf +0 -0
  72. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/white-overprint.pdf +0 -0
  73. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/pdfs/wrong-size.pdf +0 -0
  74. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/suites/README.md +0 -0
  75. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/fixtures/suites/expected.toml +0 -0
  76. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/__init__.py +0 -0
  77. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/conftest.py +0 -0
  78. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_bleed.py +0 -0
  79. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_cli.py +0 -0
  80. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_config.py +0 -0
  81. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_content.py +0 -0
  82. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_contrast.py +0 -0
  83. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_core.py +0 -0
  84. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_deltae.py +0 -0
  85. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_fixtures_current.py +0 -0
  86. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_inventory.py +0 -0
  87. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_load_profile.py +0 -0
  88. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_paint.py +0 -0
  89. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_preview.py +0 -0
  90. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_proc.py +0 -0
  91. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_resolution.py +0 -0
  92. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_structure.py +0 -0
  93. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_suites.py +0 -0
  94. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_texlog.py +0 -0
  95. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_text.py +0 -0
  96. {proof_pdf-0.3.4 → proof_pdf-0.3.6}/tests/test_proof_pdf/test_verapdf.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: proof-pdf
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Summary: Hold print PDFs to PDF/X-4 and PDF/A: veraPDF, page boxes, geometry, ink and image resolution.
5
5
  Keywords: pdf,pdf/x-4,pdf/a,verapdf,prepress,print,preflight,ghostscript,lualatex
6
6
  Author-Email: Ilja Orlovs <ilja@release.art>
@@ -50,6 +50,8 @@ Open-source pieces of a print-on-demand pipeline, extracted from production use.
50
50
  overprint and rich-black small text (`--no-colour`). Overprinting 100% K text is fine; overprint on anything else is flagged,
51
51
  and **white that overprints is an error** (it adds no ink, so it vanishes on press). A page that uses transparency must blend
52
52
  in the output intent's colour space (a mismatch is an error, an undeclared space a warning).
53
+ - **RGB proofing** (opt-in, `--colour-mode rgb`): for a screen job, CMYK images, fills, strokes, shadings and patterns and a CMYK output intent are errors, spot colours a warning;
54
+ total ink, overprint and rich-black checks are skipped. Save it as a profile: `[profiles.web.verify]` with `colour-mode = "rgb"` and `pdfx = false`, chosen with `proof-pdf --profile web verify`.
53
55
  - **K-only text** (opt-in, `--k-only-text`): text painted with any ink but K (a four-colour build, RGB, a spot or a pattern) is an error.
54
56
  - **Proofing** (the text and lines a page paints, measured in page points; see below).
55
57
 
@@ -150,6 +152,8 @@ typo cannot silently switch a check off.
150
152
  ```zsh
151
153
  proof-pdf inspect card.pdf # fonts (embedded?, .notdef), text colours and sizes, spot inks, images, contrast
152
154
  proof-pdf inspect card.pdf --json # the same as data, for other tools
155
+ proof-pdf extract old/brochure.pdf # recover images, fonts, ICC profiles, vector artwork and text into old/brochure/
156
+ proof-pdf extract old/brochure.pdf --previews # ...plus old/brochure/previews/index.html to review it
153
157
  proof-pdf texlog build/card.log # dropped characters, TeX errors, undefined references, substituted fonts, overfull boxes
154
158
  proof-pdf verify card.pdf --safe-mm 3 --min-text-pt 6 --min-delta-l 30 --proof-profile FOGRA51.icc
155
159
  ```
@@ -159,7 +163,59 @@ proof-pdf verify card.pdf --safe-mm 3 --min-text-pt 6 --min-delta-l 30 --proof-p
159
163
  undefined references are errors; font substitution, package warnings, a pending rerun and overfull boxes are warnings
160
164
  (`--max-overfull-pt N` promotes the worst overfull boxes).
161
165
 
162
- The library offers the same as data: `proof_pdf.inventory.inspect_pdf(path)` returns plain dataclasses, and the checks are
166
+ `extract` is for the archive: a customer's old PDF is all that is left of a job, and you want its logo, pictograms and
167
+ photos back. It writes `images/`, `fonts/`, `icc/` and `vector/` (one cropped PDF per piece of artwork, ready for
168
+ `\includegraphics`) and a `document.json` with the page boxes, every asset's placements in points from the page's
169
+ bottom-left, every text run with font, size, colour and position (and the runs joined into lines), and the plain rectangles and rules of
170
+ the layout.
171
+ Vector artwork has no names in a PDF, so pieces are found by grouping shapes that touch (`--gap-pt`) and ignoring
172
+ anything covering more than `--max-fraction` of the page; clips are not applied and text is not part of a piece.
173
+ `document.json` also holds what a template rebuild needs: `metadata.xmp` (the XMP packet decoded, also saved as `xmp.xml`;
174
+ InDesign writes its fonts, plates and swatches there), `palette`, and `layout`. The layout reads the page back from where
175
+ the text sits: the type styles in use and what each is for (body, heading levels, small print), the paragraphs with their
176
+ alignment, indent and spacing, the text columns, margins and content box of every page, the running headers, footers and
177
+ folios, and a `summary` of the numbers a document class takes (page size, margins, columns, gutter, measure, body font,
178
+ size and leading). It is inferred from geometry, so treat it as evidence to check against the page, not as fact; datasheets
179
+ full of tables read poorly, flowing text well.
180
+
181
+ `interactive` lists the form fields (with type, value, font and size, so a fillable certificate comes back as a form), the
182
+ links and where they go, the outline, page labels, layers and attachments. A digital signature is described by who, when
183
+ and how it was made, never copied. Text lying on a piece of artwork (dimensions on a drawing, labels on a diagram) is
184
+ drawn into that piece's PDF and listed in its `details.text`, as well as recovered as text; `--no-vector-text` leaves the
185
+ pieces as the drawn shapes alone.
186
+
187
+ `spot_colours` names every ink the file paints with and what it stands in for on screen (the tint transform evaluated at
188
+ full tint: a PANTONE usually comes back as Lab, a die-line as a CMYK tint); the printer's ink book, not this, says what the
189
+ ink really is. `layout.pages[].tables` are tables read from their rules, with cells, spans and text, so a results table or
190
+ a product list comes back as rows and columns rather than as scattered text; they need rules (a table made of whitespace
191
+ alone is not found).
192
+
193
+ For a tagged PDF (Word, InDesign and Acrobat export them), `structure` is what the producer said each piece is: which
194
+ text is a level-2 heading, where a paragraph or table cell begins and ends, a figure's alt text (the nearest thing a PDF has
195
+ to a name for an image or drawing, copied to the asset as `details.alt`), and its own alignment, indent and spacing
196
+ numbers. Where the file is tagged it is better evidence than the geometry, and the layout uses it for heading roles and
197
+ paragraph boundaries; an untagged file (`structure.tagged` is false) is read from geometry alone. Fonts carry their
198
+ descriptor facts (bold, italic, weight, flags, metrics).
199
+
200
+ `crop` is for what the extraction missed: it cuts a rectangle out of one page as a one-page PDF, exactly as the page
201
+ shows it (text stays text, vectors stay vectors, images keep their pixels).
202
+
203
+ ```zsh
204
+ proof-pdf crop old/brochure.pdf --page 14 --box 64,300,556,607 --pad-pt 2 --out figure-14.pdf
205
+ ```
206
+
207
+ The box is `X0,Y0,X1,Y1` in points from the page's bottom-left, the numbers `document.json` gives every placement (`x`, `y`,
208
+ `x + width`, `y + height`) and the review page shows under the mouse; from a preview PNG at a given dpi, a pixel is
209
+ `x = media_x0 + px / dpi * 72`, `y = media_y1 - py / dpi * 72`. In code, `proof_pdf.crop.crop_page(path, page, box, out)`.
210
+ The piece also holds the rest of the page's content outside the window, which a viewer does not show; rasterise it when
211
+ that matters.
212
+
213
+ `--previews` renders `previews/index.html` (needs Ghostscript): each page with every recovered asset boxed on it and
214
+ linked to its thumbnail below, so a whole archive job can be reviewed by eye. Text in fonts without a `/ToUnicode` map
215
+ cannot be read from the PDF; `document.json` says so in `notes` and keeps the font codes. Mind who owns the artwork you
216
+ recover.
217
+
218
+ The library offers the same as data: `proof_pdf.inventory.inspect_pdf(path)` returns plain dataclasses, `proof_pdf.extract.extract_pdf(path, out_dir)` writes the assets and returns what it found, and the checks are
163
219
  functions over an opened `pikepdf.Pdf`.
164
220
 
165
221
  ## Docker images
@@ -24,6 +24,8 @@ Open-source pieces of a print-on-demand pipeline, extracted from production use.
24
24
  overprint and rich-black small text (`--no-colour`). Overprinting 100% K text is fine; overprint on anything else is flagged,
25
25
  and **white that overprints is an error** (it adds no ink, so it vanishes on press). A page that uses transparency must blend
26
26
  in the output intent's colour space (a mismatch is an error, an undeclared space a warning).
27
+ - **RGB proofing** (opt-in, `--colour-mode rgb`): for a screen job, CMYK images, fills, strokes, shadings and patterns and a CMYK output intent are errors, spot colours a warning;
28
+ total ink, overprint and rich-black checks are skipped. Save it as a profile: `[profiles.web.verify]` with `colour-mode = "rgb"` and `pdfx = false`, chosen with `proof-pdf --profile web verify`.
27
29
  - **K-only text** (opt-in, `--k-only-text`): text painted with any ink but K (a four-colour build, RGB, a spot or a pattern) is an error.
28
30
  - **Proofing** (the text and lines a page paints, measured in page points; see below).
29
31
 
@@ -124,6 +126,8 @@ typo cannot silently switch a check off.
124
126
  ```zsh
125
127
  proof-pdf inspect card.pdf # fonts (embedded?, .notdef), text colours and sizes, spot inks, images, contrast
126
128
  proof-pdf inspect card.pdf --json # the same as data, for other tools
129
+ proof-pdf extract old/brochure.pdf # recover images, fonts, ICC profiles, vector artwork and text into old/brochure/
130
+ proof-pdf extract old/brochure.pdf --previews # ...plus old/brochure/previews/index.html to review it
127
131
  proof-pdf texlog build/card.log # dropped characters, TeX errors, undefined references, substituted fonts, overfull boxes
128
132
  proof-pdf verify card.pdf --safe-mm 3 --min-text-pt 6 --min-delta-l 30 --proof-profile FOGRA51.icc
129
133
  ```
@@ -133,7 +137,59 @@ proof-pdf verify card.pdf --safe-mm 3 --min-text-pt 6 --min-delta-l 30 --proof-p
133
137
  undefined references are errors; font substitution, package warnings, a pending rerun and overfull boxes are warnings
134
138
  (`--max-overfull-pt N` promotes the worst overfull boxes).
135
139
 
136
- The library offers the same as data: `proof_pdf.inventory.inspect_pdf(path)` returns plain dataclasses, and the checks are
140
+ `extract` is for the archive: a customer's old PDF is all that is left of a job, and you want its logo, pictograms and
141
+ photos back. It writes `images/`, `fonts/`, `icc/` and `vector/` (one cropped PDF per piece of artwork, ready for
142
+ `\includegraphics`) and a `document.json` with the page boxes, every asset's placements in points from the page's
143
+ bottom-left, every text run with font, size, colour and position (and the runs joined into lines), and the plain rectangles and rules of
144
+ the layout.
145
+ Vector artwork has no names in a PDF, so pieces are found by grouping shapes that touch (`--gap-pt`) and ignoring
146
+ anything covering more than `--max-fraction` of the page; clips are not applied and text is not part of a piece.
147
+ `document.json` also holds what a template rebuild needs: `metadata.xmp` (the XMP packet decoded, also saved as `xmp.xml`;
148
+ InDesign writes its fonts, plates and swatches there), `palette`, and `layout`. The layout reads the page back from where
149
+ the text sits: the type styles in use and what each is for (body, heading levels, small print), the paragraphs with their
150
+ alignment, indent and spacing, the text columns, margins and content box of every page, the running headers, footers and
151
+ folios, and a `summary` of the numbers a document class takes (page size, margins, columns, gutter, measure, body font,
152
+ size and leading). It is inferred from geometry, so treat it as evidence to check against the page, not as fact; datasheets
153
+ full of tables read poorly, flowing text well.
154
+
155
+ `interactive` lists the form fields (with type, value, font and size, so a fillable certificate comes back as a form), the
156
+ links and where they go, the outline, page labels, layers and attachments. A digital signature is described by who, when
157
+ and how it was made, never copied. Text lying on a piece of artwork (dimensions on a drawing, labels on a diagram) is
158
+ drawn into that piece's PDF and listed in its `details.text`, as well as recovered as text; `--no-vector-text` leaves the
159
+ pieces as the drawn shapes alone.
160
+
161
+ `spot_colours` names every ink the file paints with and what it stands in for on screen (the tint transform evaluated at
162
+ full tint: a PANTONE usually comes back as Lab, a die-line as a CMYK tint); the printer's ink book, not this, says what the
163
+ ink really is. `layout.pages[].tables` are tables read from their rules, with cells, spans and text, so a results table or
164
+ a product list comes back as rows and columns rather than as scattered text; they need rules (a table made of whitespace
165
+ alone is not found).
166
+
167
+ For a tagged PDF (Word, InDesign and Acrobat export them), `structure` is what the producer said each piece is: which
168
+ text is a level-2 heading, where a paragraph or table cell begins and ends, a figure's alt text (the nearest thing a PDF has
169
+ to a name for an image or drawing, copied to the asset as `details.alt`), and its own alignment, indent and spacing
170
+ numbers. Where the file is tagged it is better evidence than the geometry, and the layout uses it for heading roles and
171
+ paragraph boundaries; an untagged file (`structure.tagged` is false) is read from geometry alone. Fonts carry their
172
+ descriptor facts (bold, italic, weight, flags, metrics).
173
+
174
+ `crop` is for what the extraction missed: it cuts a rectangle out of one page as a one-page PDF, exactly as the page
175
+ shows it (text stays text, vectors stay vectors, images keep their pixels).
176
+
177
+ ```zsh
178
+ proof-pdf crop old/brochure.pdf --page 14 --box 64,300,556,607 --pad-pt 2 --out figure-14.pdf
179
+ ```
180
+
181
+ The box is `X0,Y0,X1,Y1` in points from the page's bottom-left, the numbers `document.json` gives every placement (`x`, `y`,
182
+ `x + width`, `y + height`) and the review page shows under the mouse; from a preview PNG at a given dpi, a pixel is
183
+ `x = media_x0 + px / dpi * 72`, `y = media_y1 - py / dpi * 72`. In code, `proof_pdf.crop.crop_page(path, page, box, out)`.
184
+ The piece also holds the rest of the page's content outside the window, which a viewer does not show; rasterise it when
185
+ that matters.
186
+
187
+ `--previews` renders `previews/index.html` (needs Ghostscript): each page with every recovered asset boxed on it and
188
+ linked to its thumbnail below, so a whole archive job can be reviewed by eye. Text in fonts without a `/ToUnicode` map
189
+ cannot be read from the PDF; `document.json` says so in `notes` and keeps the font codes. Mind who owns the artwork you
190
+ recover.
191
+
192
+ The library offers the same as data: `proof_pdf.inventory.inspect_pdf(path)` returns plain dataclasses, `proof_pdf.extract.extract_pdf(path, out_dir)` writes the assets and returns what it found, and the checks are
137
193
  functions over an opened `pikepdf.Pdf`.
138
194
 
139
195
  ## Docker images
@@ -37,7 +37,7 @@ dependencies = [
37
37
  "pillow>=12.3.0",
38
38
  "typer>=0.27.3",
39
39
  ]
40
- version = "0.3.4"
40
+ version = "0.3.6"
41
41
 
42
42
  [project.urls]
43
43
  Homepage = "https://github.com/release-art/proofpress"
@@ -8,8 +8,10 @@ coverage, overprint, rich-black small text, stray RGB, effective image DPI).
8
8
  The entry point is :func:`proof_pdf.core.verify_file`; the CLI group lives in
9
9
  :mod:`proof_pdf.cli` and is the ``proof-pdf`` console script.
10
10
 
11
- Public API is the top-level modules (:mod:`~proof_pdf.core`, :mod:`~proof_pdf.models`, :mod:`~proof_pdf.inventory`,
12
- :mod:`~proof_pdf.preview`, :mod:`~proof_pdf.texlog`, :mod:`~proof_pdf.config`, :mod:`~proof_pdf.cli`) and the
11
+ Public API is the top-level modules (:mod:`~proof_pdf.core`, :mod:`~proof_pdf.models`,
12
+ :mod:`~proof_pdf.inventory`,
13
+ :mod:`~proof_pdf.extract`, :mod:`~proof_pdf.crop`, :mod:`~proof_pdf.layout`, :mod:`~proof_pdf.preview`,
14
+ :mod:`~proof_pdf.texlog`, :mod:`~proof_pdf.config`, :mod:`~proof_pdf.cli`) and the
13
15
  :func:`~proof_pdf.config.load_profile` re-export. Everything under ``proof_pdf._internal`` (the checks, the content and
14
16
  paint walks, the tool wrappers, the config reader) is private and may change at any time.
15
17
 
@@ -35,7 +35,7 @@ import pikepdf
35
35
  from PIL import Image, ImageMath
36
36
 
37
37
  from ..models import Finding, Severity
38
- from . import content, proc
38
+ from . import proc
39
39
  from .paint import Fill, Walker, paint_events
40
40
  from .spaces import CMYK, GRAY, RGB, classify_colour_space, intent_family
41
41
 
@@ -255,15 +255,7 @@ def check_colour_spaces(pdf: pikepdf.Pdf, *, strict: bool) -> list[Finding]:
255
255
  findings: list[Finding] = []
256
256
  vector_severity = Severity.ERROR if strict else Severity.WARN
257
257
  for i, page in enumerate(pdf.pages, start=1):
258
- images: set[str] = set()
259
- vector = False
260
- for op in content.iter_operations(page):
261
- if op.operator in ("rg", "RG"):
262
- vector = True
263
- elif op.operator == "Do":
264
- name = _rgb_image_name(op)
265
- if name is not None:
266
- images.add(name)
258
+ images, colours, _ = _paint_in(page, RGB)
267
259
  for name in sorted(images):
268
260
  findings.append(
269
261
  Finding(
@@ -273,26 +265,64 @@ def check_colour_spaces(pdf: pikepdf.Pdf, *, strict: bool) -> list[Finding]:
273
265
  i,
274
266
  )
275
267
  )
276
- if vector:
268
+ if colours:
277
269
  findings.append(
278
270
  Finding(
279
271
  "colour-space",
280
272
  vector_severity,
281
- "vector artwork is filled in DeviceRGB -- confirm the RIP is meant to convert it",
273
+ "vector artwork is painted in RGB -- confirm the RIP is meant to convert it",
282
274
  i,
283
275
  )
284
276
  )
285
277
  return findings
286
278
 
287
279
 
288
- def _rgb_image_name(op: content.Operation) -> str | None:
289
- """The name of the image this ``Do`` paints, if that image is in an RGB space."""
290
- xobject = content.lookup_xobject(op.resources, op.operands)
291
- if xobject is None or str(xobject.get("/Subtype")) != "/Image":
292
- return None
293
- if classify_colour_space(xobject.get("/ColorSpace"), op.resources) != RGB:
294
- return None
295
- return str(op.operands[0])
280
+ # ------------------------------------------------------------ RGB proofing ----
281
+ def check_rgb_only(pdf: pikepdf.Pdf) -> list[Finding]:
282
+ """For a screen job: flag CMYK images and fills, a CMYK output intent, and (as advisory) spot colours.
283
+
284
+ Gray is colour-neutral and passes. Shadings and patterns are looked through to the colour space they paint in.
285
+ """
286
+ findings: list[Finding] = []
287
+ if intent_family(pdf) == CMYK:
288
+ findings.append(Finding("rgb-only", Severity.ERROR, "the output intent is a CMYK profile in an RGB job"))
289
+ for i, page in enumerate(pdf.pages, start=1):
290
+ images, fills, spots = _paint_in(page, CMYK)
291
+ for name in sorted(images):
292
+ findings.append(Finding("rgb-only", Severity.ERROR, f"image {name} is in a CMYK colour space", i))
293
+ if fills:
294
+ findings.append(
295
+ Finding(
296
+ "rgb-only", Severity.ERROR, f"artwork is painted in CMYK ({', '.join(sorted(fills)[:3])}...)", i
297
+ )
298
+ )
299
+ if spots:
300
+ findings.append(
301
+ Finding("rgb-only", Severity.WARN, f"spot colour(s) {', '.join(sorted(spots))} have no RGB value", i)
302
+ )
303
+ return findings
304
+
305
+
306
+ def _paint_in(page: pikepdf.Page, family: str) -> tuple[set[str], set[str], set[str]]:
307
+ """The image names and colour descriptions in *family*, and the spot ink names, a page paints by fill or stroke."""
308
+ images: set[str] = set()
309
+ colours: set[str] = set()
310
+ spots: set[str] = set()
311
+ for p in paint_events(page):
312
+ if p.kind in ("image", "inline-image") and not p.mask:
313
+ if p.colour_space == family:
314
+ images.add(p.name)
315
+ continue
316
+ if p.kind == "shading":
317
+ if p.colour_space == family:
318
+ colours.add(f"shading {p.name}")
319
+ continue
320
+ for colour in p.colours():
321
+ if colour.family == family or family in colour.pattern:
322
+ colours.add(_describe(colour))
323
+ elif colour.spot:
324
+ spots.update(colour.spot)
325
+ return images, colours, spots
296
326
 
297
327
 
298
328
  # ------------------------------------------------ rich-black small text ----
@@ -359,6 +389,8 @@ def _is_full_k(fill: Fill) -> bool:
359
389
 
360
390
 
361
391
  def _describe(fill: Fill) -> str:
392
+ if fill.pattern:
393
+ return "a pattern using " + "/".join(sorted(f.upper() for f in fill.pattern))
362
394
  if fill.family == CMYK and len(fill.value) >= 4:
363
395
  c, m, y, k = (round(v * 100) for v in fill.value[:4])
364
396
  return f"C{c} M{m} Y{y} K{k}"
@@ -85,18 +85,19 @@ def horizontal_scale(m: Matrix) -> float:
85
85
 
86
86
 
87
87
  def iter_operations(
88
- page: pikepdf.Page,
88
+ page: pikepdf.Page | pikepdf.Object,
89
89
  *,
90
90
  max_depth: int = DEFAULT_MAX_DEPTH,
91
91
  ) -> collections.abc.Iterator[Operation]:
92
- """Yield every operator on *page*, descending into Form XObjects.
92
+ """Yield every operator on *page* (or a pattern or form stream), descending into Form XObjects.
93
93
 
94
94
  The CTM carried by each :class:`Operation` reflects the ``q``/``Q``/``cm``
95
95
  state at that point, with each enclosing form's ``/Matrix`` already folded
96
96
  in -- so a consumer can convert directly from user space to page points
97
97
  without knowing how deeply nested it is.
98
98
  """
99
- resources = page.obj.get("/Resources")
99
+ # A page, or any content stream with its own /Resources (a tiling pattern's, say).
100
+ resources = (page.obj if isinstance(page, pikepdf.Page) else page).get("/Resources")
100
101
  yield from _walk(page, resources, IDENTITY, 0, frozenset(), max_depth)
101
102
 
102
103
 
@@ -159,6 +159,9 @@ def describe(fill: Fill | None) -> str:
159
159
  if fill.family == RGB and len(fill.value) >= 3:
160
160
  r, g, b = (round(v * 255) for v in fill.value[:3])
161
161
  return f"RGB({r},{g},{b})"
162
+ if fill.spot:
163
+ tint = f" {round(fill.value[0] * 100)}%" if len(fill.spot) == 1 and fill.value else ""
164
+ return f"spot {'+'.join(fill.spot)}{tint}"
162
165
  return "a spot or pattern colour"
163
166
 
164
167
 
@@ -14,6 +14,8 @@ import pikepdf
14
14
 
15
15
  _SUBSET_PREFIX = re.compile(r"^[A-Z]{6}\+")
16
16
  _IDENTITY = ("/Identity-H", "/Identity-V")
17
+ _ADOBE_COLLECTIONS = ("GB1", "CNS1", "Korea1") # Japan1 differs from ASCII at a few Latin CIDs, so it is left out
18
+ _ADOBE_LATIN_CIDS, _ADOBE_LATIN_OFFSET = 95, 31 # CID 1 is the space, U+0020
17
19
  _FALLBACK_WIDTH = 500.0 # per 1000 em; typical of a text face
18
20
  _DEFAULT_ASCENT, _DEFAULT_DESCENT = 800.0, -200.0
19
21
 
@@ -32,6 +34,19 @@ class Font:
32
34
  descent: float = _DEFAULT_DESCENT
33
35
  composite: bool = False
34
36
  decodable: bool = True # False for a composite font whose encoding is not Identity: codes can't be split reliably
37
+ to_unicode: dict[int, str] = dataclasses.field(default_factory=dict)
38
+ adobe_latin: bool = False # an Adobe GB1/CNS1/Korea1 CID font: CIDs 1-95 are ASCII 0x20-0x7E by definition
39
+
40
+ def text(self, codes: list[int]) -> str | None:
41
+ """The characters *codes* show: from ``/ToUnicode``, else (for an Adobe CJK collection) the Latin CIDs, else
42
+ Latin-1 for a simple font, else ``None`` (unknown)."""
43
+ if self.to_unicode or self.adobe_latin:
44
+ shown = [self.to_unicode.get(code) or self._latin(code) or "\N{REPLACEMENT CHARACTER}" for code in codes]
45
+ return "".join(shown) if self.to_unicode or any(c != "\N{REPLACEMENT CHARACTER}" for c in shown) else None
46
+ return None if self.composite else bytes(code & 0xFF for code in codes).decode("latin-1")
47
+
48
+ def _latin(self, code: int) -> str | None:
49
+ return chr(code + _ADOBE_LATIN_OFFSET) if self.adobe_latin and 1 <= code <= _ADOBE_LATIN_CIDS else None
35
50
 
36
51
  def decode(self, data: bytes) -> list[int]:
37
52
  """The character codes in a shown string."""
@@ -82,6 +97,7 @@ def _load(font: pikepdf.Object) -> Font:
82
97
  default_width=missing or (_FALLBACK_WIDTH if not widths else 0.0),
83
98
  widths=widths,
84
99
  notdef_codes=_notdef_codes(font.get("/Encoding")),
100
+ to_unicode=_to_unicode(font.get("/ToUnicode")),
85
101
  ascent=float(descriptor.get("/Ascent", _DEFAULT_ASCENT)) if descriptor is not None else _DEFAULT_ASCENT,
86
102
  descent=float(descriptor.get("/Descent", _DEFAULT_DESCENT)) if descriptor is not None else _DEFAULT_DESCENT,
87
103
  )
@@ -101,13 +117,61 @@ def _load_composite(font: pikepdf.Object, name: str) -> Font:
101
117
  default_width=float(descendant.get("/DW", 1000)),
102
118
  widths=_cid_widths(descendant.get("/W")),
103
119
  notdef_codes=frozenset(),
120
+ to_unicode=_to_unicode(font.get("/ToUnicode")),
104
121
  ascent=float(descriptor.get("/Ascent", _DEFAULT_ASCENT)) if descriptor is not None else _DEFAULT_ASCENT,
105
122
  descent=float(descriptor.get("/Descent", _DEFAULT_DESCENT)) if descriptor is not None else _DEFAULT_DESCENT,
106
123
  composite=True,
107
124
  decodable=identity,
125
+ adobe_latin=identity and _adobe_collection(descendant),
126
+ )
127
+
128
+
129
+ def _adobe_collection(descendant: pikepdf.Object) -> bool:
130
+ info = descendant.get("/CIDSystemInfo")
131
+ return (
132
+ info is not None and str(info.get("/Registry")) == "Adobe" and str(info.get("/Ordering")) in _ADOBE_COLLECTIONS
108
133
  )
109
134
 
110
135
 
136
+ _BF_CHAR = re.compile(rb"beginbfchar(.*?)endbfchar", re.DOTALL)
137
+ _BF_RANGE = re.compile(rb"beginbfrange(.*?)endbfrange", re.DOTALL)
138
+ _BF_TOKEN = re.compile(rb"<[^>]*>|\[|\]")
139
+
140
+
141
+ def _hex(token: bytes) -> bytes:
142
+ return bytes.fromhex(re.sub(rb"[<>\s]", b"", token).decode())
143
+
144
+
145
+ def _to_unicode(stream: pikepdf.Object | None) -> dict[int, str]:
146
+ """A ``/ToUnicode`` CMap's ``bfchar`` and ``bfrange`` entries as code -> text; empty if absent or unreadable."""
147
+ if stream is None:
148
+ return {}
149
+ try:
150
+ data = bytes(stream.read_bytes())
151
+ mapping: dict[int, str] = {}
152
+ for block in _BF_CHAR.findall(data):
153
+ tokens = _BF_TOKEN.findall(block)
154
+ for src, dst in zip(tokens[::2], tokens[1::2], strict=False):
155
+ mapping[int.from_bytes(_hex(src))] = _hex(dst).decode("utf-16-be", "replace")
156
+ for block in _BF_RANGE.findall(data):
157
+ tokens, i = _BF_TOKEN.findall(block), 0
158
+ while i + 2 < len(tokens):
159
+ low, high = int.from_bytes(_hex(tokens[i])), int.from_bytes(_hex(tokens[i + 1]))
160
+ if tokens[i + 2] == b"[":
161
+ end = tokens.index(b"]", i + 2)
162
+ for code, dst in zip(range(low, high + 1), tokens[i + 3 : end], strict=False):
163
+ mapping[code] = _hex(dst).decode("utf-16-be", "replace")
164
+ i = end + 1
165
+ else:
166
+ base = _hex(tokens[i + 2]).decode("utf-16-be", "replace")
167
+ for offset in range(min(high - low, 0xFFFF) + 1):
168
+ mapping[low + offset] = base[:-1] + chr(ord(base[-1]) + offset) if base else ""
169
+ i += 3
170
+ return mapping
171
+ except pikepdf.PdfError, ValueError, IndexError, TypeError, OverflowError:
172
+ return {}
173
+
174
+
111
175
  def _embedded(descriptor: pikepdf.Object | None) -> bool:
112
176
  return descriptor is not None and any(k in descriptor for k in ("/FontFile", "/FontFile2", "/FontFile3"))
113
177