html-to-native-pptx 0.1.1__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 (54) hide show
  1. html_to_native_pptx-0.1.1/.gitattributes +3 -0
  2. html_to_native_pptx-0.1.1/.github/workflows/publish.yml +21 -0
  3. html_to_native_pptx-0.1.1/.gitignore +10 -0
  4. html_to_native_pptx-0.1.1/LICENSE +21 -0
  5. html_to_native_pptx-0.1.1/PKG-INFO +243 -0
  6. html_to_native_pptx-0.1.1/README.md +221 -0
  7. html_to_native_pptx-0.1.1/benchmark/adapters/dom_to_pptx.py +50 -0
  8. html_to_native_pptx-0.1.1/benchmark/ground.py +103 -0
  9. html_to_native_pptx-0.1.1/benchmark/lofonts.py +39 -0
  10. html_to_native_pptx-0.1.1/benchmark/run.py +158 -0
  11. html_to_native_pptx-0.1.1/benchmark/run.sh +11 -0
  12. html_to_native_pptx-0.1.1/benchmark/score.py +316 -0
  13. html_to_native_pptx-0.1.1/benchmark/visual.py +58 -0
  14. html_to_native_pptx-0.1.1/corpus/chart-draw.js +30 -0
  15. html_to_native_pptx-0.1.1/corpus/deck.html +108 -0
  16. html_to_native_pptx-0.1.1/corpus/fonts/DMSerifDisplay-Italic.ttf +0 -0
  17. html_to_native_pptx-0.1.1/corpus/fonts/DMSerifDisplay-Regular.ttf +0 -0
  18. html_to_native_pptx-0.1.1/corpus/fonts/IBMPlexMono-Medium.ttf +0 -0
  19. html_to_native_pptx-0.1.1/corpus/fonts/IBMPlexMono-Regular.ttf +0 -0
  20. html_to_native_pptx-0.1.1/corpus/fonts/Inter-Variable.ttf +0 -0
  21. html_to_native_pptx-0.1.1/corpus/fonts/OFL-dmserifdisplay.txt +93 -0
  22. html_to_native_pptx-0.1.1/corpus/fonts/OFL-ibmplexmono.txt +93 -0
  23. html_to_native_pptx-0.1.1/corpus/fonts/OFL-inter.txt +93 -0
  24. html_to_native_pptx-0.1.1/corpus/images/backdrop.jpg +0 -0
  25. html_to_native_pptx-0.1.1/corpus/images/card.jpg +0 -0
  26. html_to_native_pptx-0.1.1/corpus/make_images.py +35 -0
  27. html_to_native_pptx-0.1.1/docker/dev.Dockerfile +9 -0
  28. html_to_native_pptx-0.1.1/docker/dev.sh +7 -0
  29. html_to_native_pptx-0.1.1/docs/charts.md +59 -0
  30. html_to_native_pptx-0.1.1/pyproject.toml +72 -0
  31. html_to_native_pptx-0.1.1/src/html_to_native_pptx/__init__.py +32 -0
  32. html_to_native_pptx-0.1.1/src/html_to_native_pptx/__main__.py +7 -0
  33. html_to_native_pptx-0.1.1/src/html_to_native_pptx/assets/measure.js +497 -0
  34. html_to_native_pptx-0.1.1/src/html_to_native_pptx/cli.py +75 -0
  35. html_to_native_pptx-0.1.1/src/html_to_native_pptx/convert.py +89 -0
  36. html_to_native_pptx-0.1.1/src/html_to_native_pptx/errors.py +5 -0
  37. html_to_native_pptx-0.1.1/src/html_to_native_pptx/fontfiles.py +93 -0
  38. html_to_native_pptx-0.1.1/src/html_to_native_pptx/fonts.py +442 -0
  39. html_to_native_pptx-0.1.1/src/html_to_native_pptx/measurer.py +149 -0
  40. html_to_native_pptx-0.1.1/src/html_to_native_pptx/model.py +241 -0
  41. html_to_native_pptx-0.1.1/src/html_to_native_pptx/pages.py +87 -0
  42. html_to_native_pptx-0.1.1/src/html_to_native_pptx/py.typed +0 -0
  43. html_to_native_pptx-0.1.1/src/html_to_native_pptx/writer/__init__.py +78 -0
  44. html_to_native_pptx-0.1.1/src/html_to_native_pptx/writer/charts.py +251 -0
  45. html_to_native_pptx-0.1.1/src/html_to_native_pptx/writer/colour.py +34 -0
  46. html_to_native_pptx-0.1.1/src/html_to_native_pptx/writer/pictures.py +13 -0
  47. html_to_native_pptx-0.1.1/src/html_to_native_pptx/writer/shapes.py +78 -0
  48. html_to_native_pptx-0.1.1/src/html_to_native_pptx/writer/tables.py +96 -0
  49. html_to_native_pptx-0.1.1/src/html_to_native_pptx/writer/text.py +161 -0
  50. html_to_native_pptx-0.1.1/src/html_to_native_pptx/writer/units.py +20 -0
  51. html_to_native_pptx-0.1.1/tests/test_convert.py +203 -0
  52. html_to_native_pptx-0.1.1/tests/test_fonts.py +216 -0
  53. html_to_native_pptx-0.1.1/tests/test_writer.py +392 -0
  54. html_to_native_pptx-0.1.1/uv.lock +1243 -0
@@ -0,0 +1,3 @@
1
+ *.ttf binary
2
+ *.jpg binary
3
+ *.txt text eol=lf
@@ -0,0 +1,21 @@
1
+ # Publish to PyPI when a GitHub release is published, with PyPI trusted publishing:
2
+ # GitHub proves to PyPI that this workflow is running, so no token is stored anywhere.
3
+ # One-time setup on pypi.org: add a trusted publisher for this repository, workflow
4
+ # "publish.yml", environment "pypi".
5
+ name: Publish
6
+
7
+ on:
8
+ release:
9
+ types: [published]
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+ environment: pypi
15
+ permissions:
16
+ id-token: write
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: astral-sh/setup-uv@v6
20
+ - run: uv build
21
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,10 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .mypy_cache/
5
+ .ruff_cache/
6
+ .pytest_cache/
7
+ dist/
8
+ benchmark/out/
9
+ *.pptx
10
+ !tests/**/*.pptx
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 hollee-tom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,243 @@
1
+ Metadata-Version: 2.5
2
+ Name: html-to-native-pptx
3
+ Version: 0.1.1
4
+ Summary: High-fidelity HTML to native, editable PowerPoint.
5
+ Project-URL: Homepage, https://github.com/hollee-tom/html-to-native-pptx
6
+ Project-URL: Repository, https://github.com/hollee-tom/html-to-native-pptx
7
+ Project-URL: Issues, https://github.com/hollee-tom/html-to-native-pptx/issues
8
+ Author: hollee-tom
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: editable,export,html,html-to-pptx,playwright,powerpoint,pptx,slides
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Office/Business
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.11
16
+ Requires-Dist: brotli>=1.1
17
+ Requires-Dist: fonttools>=4.50
18
+ Requires-Dist: playwright>=1.49
19
+ Requires-Dist: pydantic>=2.6
20
+ Requires-Dist: python-pptx>=1.0
21
+ Description-Content-Type: text/markdown
22
+
23
+ # html-to-native-pptx
24
+
25
+ **High-fidelity HTML to native, editable PowerPoint.**
26
+
27
+ html-to-native-pptx opens a deck of HTML slides in Chromium, measures what the browser actually drew, and
28
+ writes a `.pptx` whose contents are real PowerPoint objects:
29
+
30
+ - **Text** stays text: text boxes with runs, fonts, sizes, colours, letter-spacing, bullets,
31
+ links, super/subscript, and inline chips and marked words as run highlights.
32
+ - **Tables** stay tables: native tables with merged cells, fills and per-side borders.
33
+ - **Shapes** stay shapes: rectangles, rounded rectangles, ellipses and lines, with fill, outline,
34
+ opacity and rotation.
35
+ - **Charts** stay charts: figures that follow a small markup format become native PowerPoint
36
+ charts with editable data ([format](docs/charts.md)).
37
+ - **Pictures are only a fallback**, for what PowerPoint cannot express (a gradient, an SVG, a
38
+ photograph, a `::before` decoration). Each is a transparent picture of just that element,
39
+ placed *behind* the native text, so the text on top is still yours to edit.
40
+
41
+ It is not a slide-screenshot exporter: a deck made of one picture per slide is not "native".
42
+
43
+ ## Quick start
44
+
45
+ ```sh
46
+ pip install html-to-native-pptx
47
+ playwright install chromium
48
+ html-to-native-pptx deck.html -o deck.pptx
49
+ ```
50
+
51
+ ```python
52
+ from pathlib import Path
53
+ from html_to_native_pptx import convert
54
+
55
+ convert(Path("deck.html"), Path("deck.pptx"), slide_selector="section", width=1280, height=720)
56
+ ```
57
+
58
+ `html` may be a `Path` to a file, or a string of markup (pass `base_dir=` so its relative links
59
+ resolve). Every element matching `slide_selector` is one slide of `width` x `height` CSS pixels.
60
+
61
+ ```text
62
+ html-to-native-pptx deck.html -o deck.pptx
63
+ -s, --slide-selector SELECTOR CSS selector of one slide (default: section)
64
+ --width / --height PX slide size in CSS pixels (default: 1280x720)
65
+ --no-embed-fonts name fonts only; do not embed them
66
+ --no-freeze-animations measure animations as they stand
67
+ --chromium PATH a Chromium binary to drive (or set HTML_TO_NATIVE_PPTX_CHROMIUM)
68
+ --timeout SECONDS how long to wait on the page (default: 60)
69
+ ```
70
+
71
+ `html_to_native_pptx.measure(...)` returns the measurements (a pydantic `MeasuredDeck`) without writing a
72
+ file, and `html_to_native_pptx.deck_pptx(deck)` writes one from measurements, with no browser needed.
73
+
74
+ ## How it works
75
+
76
+ 1. **Measure in the browser.** Playwright loads the page as a browser does (scripts run, images
77
+ and fonts load from wherever they point). A script walks each slide's DOM and records, from
78
+ computed styles and layout, every text run, table, chart, shape and picture, in slide pixels.
79
+ 2. **Capture pictures.** Each element PowerPoint cannot express is screenshot on its own with
80
+ everything else hidden, over a transparent background. Elements with a background image or
81
+ gradient are shot with their text made clear, so the text can stay native on top.
82
+ 3. **Write natively.** python-pptx writes the objects at the measured positions. Small, targeted
83
+ XML edits cover what it lacks: alpha, highlights, the "No Style, No Grid" table style,
84
+ explicit no-line cell sides, and embedded fonts.
85
+
86
+ Code layout: `pages.py` (loading), `assets/measure.js` (the in-browser measurer),
87
+ `measurer.py` (drives it and takes the pictures), `model.py` (the measured-deck contract),
88
+ `fontfiles.py` and `fonts.py` (font discovery and embedding), `writer/` (one module each for
89
+ text, shapes, tables, charts, pictures, plus colour and units), `convert.py` and `cli.py`.
90
+
91
+ ### What it gets right that others often don't
92
+
93
+ - **See-through colours.** A faint tint behind text stays a faint tint, and an element's
94
+ `opacity` carries through, because PowerPoint has no group opacity of its own.
95
+ - **Borders on some sides.** A rule above a card stays a rule. It isn't drawn as a box around
96
+ the whole card.
97
+ - **Badges and highlighted words** keep their background, including in table cells, and the
98
+ paragraph stays one editable paragraph.
99
+ - **Spacing between inline pieces.** "01" and "Agenda" set apart with margin stay apart.
100
+ - **Content in empty-looking wrappers.** A wrapper with no height of its own, whose children are
101
+ positioned freely, still has its children exported.
102
+ - **No surprise styling from PowerPoint.** Shapes don't pick up the theme's shadow, and tables
103
+ don't pick up PowerPoint's default grid lines.
104
+ - **Odd input doesn't break the file.** A chart with no rows is skipped, and an absurd `colspan`
105
+ is capped.
106
+
107
+ ## Fonts
108
+
109
+ By default, the fonts your page uses are embedded in the `.pptx`. The slides then look right
110
+ on a computer that doesn't have those fonts installed. Turn this off with `--no-embed-fonts`.
111
+
112
+ - **It uses the fonts your page loaded**, wherever they came from: a font service such as
113
+ Google Fonts, a CDN, or local files. There's nothing to configure.
114
+ - **Each piece of text gets the exact font file the browser used**, named the way PowerPoint
115
+ expects. For example, a 300 weight becomes "Inter Light", so PowerPoint finds it.
116
+ - **Variable fonts work.** Many viewers draw a variable font at its default weight, which is
117
+ often the boldest. So each weight your slides use is saved as its own fixed font.
118
+ - **Font licences are respected.** A font that doesn't allow embedding is named in the file but
119
+ not included.
120
+ - **Not yet checked in PowerPoint.** Embedded fonts have been verified in LibreOffice. PowerPoint,
121
+ Keynote and Google Slides haven't been tested yet.
122
+
123
+ ## Supported CSS and markup
124
+
125
+ Text: font family, size, weight, style, colour, `letter-spacing`, `text-transform`,
126
+ `text-align`, `line-height`, underline, strike-through, `vertical-align: super/sub`, links,
127
+ `<br>`, `<ul>`/`<ol>` with nesting, blockquotes and `<cite>`. Inline elements with a background,
128
+ margin, padding or border become highlights and gaps. Gradient-clipped text
129
+ (`background-clip: text`) stays editable.
130
+
131
+ Boxes: background colour (with alpha), border (all sides, or per side), `border-radius`, `opacity`
132
+ (own and inherited), 2D `transform: rotate()` and scale, absolutely positioned and zero-height
133
+ wrappers, flex and grid layouts (anything the browser lays out is measured where it landed),
134
+ full-slide background images and translucent overlays. `data-shape="ellipse|line|rect"` hints a
135
+ plain shape.
136
+
137
+ Tables: `colspan`, `rowspan`, cell fills, per-side borders, vertical alignment, captions.
138
+
139
+ Charts: `figure[data-chart]` with a `table[data-chart-data]`, see [docs/charts.md](docs/charts.md).
140
+
141
+ Pictures (fallback): `<img>`, inline `<svg>`, elements with `background-image` or a gradient,
142
+ and elements with `::before`/`::after` content.
143
+
144
+ ## Known gaps
145
+
146
+ - **Inline rotated badges.** A rotated `inline-block` inside a line of text is flattened into the
147
+ paragraph: its rotation and border are lost (a rotated *block* is fine).
148
+ - **Dashed and dotted borders** are drawn solid.
149
+ - **Box shadows** are not drawn.
150
+ - **Pseudo-elements that paint outside their element's box** are clipped to the box when
151
+ pictured.
152
+ - **Hyperlinks** take the presentation theme's link colour in PowerPoint and LibreOffice, not the
153
+ CSS colour.
154
+ - **Gradient-clipped text** is editable, but the gradient lives in the picture behind it and the
155
+ native text on top is clear; edited text does not change the picture.
156
+ - **Pictures are 1x** device pixels, so a pictured photograph is as sharp as the page showed it.
157
+ - **3D transforms, filters, `mix-blend-mode`, `clip-path`** are not represented.
158
+ - **Line breaks can differ** where PowerPoint's text layout differs from the browser's; text
159
+ that the browser set on one line is kept on one line.
160
+ - **PowerPoint itself is untested**; see Fonts and the benchmark notes.
161
+
162
+ ## Benchmark
163
+
164
+ We compared html-to-native-pptx with four other open-source HTML-to-PowerPoint converters on 193
165
+ real slides, then on a public test deck anyone can rerun.
166
+
167
+ **What it shows**
168
+
169
+ - **Closest to the original.** Its slides look the most like the HTML of the five tools.
170
+ - **No lost text.** It kept every word. The other tools lost or ran together 60 to 408 words.
171
+ - **Most stays editable.** Tables stay real PowerPoint tables, borders stay lines, and charts stay
172
+ charts. Other tools turn some of these into pictures or plain text.
173
+ - **Your fonts come with the file.** It embeds the deck's own fonts, so slides look right on a
174
+ computer that doesn't have them installed.
175
+
176
+ **How much to trust it**
177
+
178
+ - The slides were checked by opening them in LibreOffice, not PowerPoint. PowerPoint may wrap a
179
+ line or space a letter slightly differently. We haven't yet tested opening the files in
180
+ PowerPoint, Keynote or Google Slides.
181
+ - The 193 real slides all came from one product's decks. HTML written another way may use CSS
182
+ these decks don't, so check your own slides.
183
+ - Each tool was run once. Small differences, about half a point on the visual score, are noise.
184
+
185
+ ### On 193 real slides
186
+
187
+ These are 8 private decks, so only the totals are published.
188
+
189
+ | | **html-to-native-pptx** | dom-to-pptx | SlideSmith | html-to-pptx | html-to-editable-pptx |
190
+ |---|---|---|---|---|---|
191
+ | Visual difference from the HTML (lower is better) | **5.2** | 6.2 | 7.3 | 7.4 | 8.2 |
192
+ | Slides that look clearly different | **3** | **3** | 10 | 4 | 12 |
193
+ | Words lost or run together (of 24,508) | **0** | 90 | 90 | 146 | 558 |
194
+ | Tables kept as tables (of 116) | **116** | **116** | **116** | 0 | 0 |
195
+ | Parts turned into pictures (fewer is more editable) | **184** | 359 | 359 | **184** | **184** |
196
+ | Letter-spacing kept | **100%** | **100%** | **100%** | 97% | 97% |
197
+ | See-through colours kept | **99%** | **99%** | **99%** | 0% | 0% |
198
+ | Rotated elements kept | 96% | **100%** | 96% | **100%** | 91% |
199
+
200
+ The visual difference is the average grey-level difference per pixel between the HTML and the
201
+ PowerPoint slide, on a 0 to 255 scale. A slide counts as clearly different above 15.
202
+
203
+ ### On the public test deck
204
+
205
+ `corpus/deck.html` is 21 slides of original HTML, built to recreate the hard cases found in real
206
+ decks: badges and highlights, see-through colours, rotation, letter-spacing, one-sided borders,
207
+ gradient headings, photo backgrounds with overlays, charts and web fonts. Its fonts are openly
208
+ licensed and their licences are in `corpus/fonts/`.
209
+
210
+ | | **html-to-native-pptx** | dom-to-pptx |
211
+ |---|---|---|
212
+ | Visual difference from the HTML (lower is better) | **4.6** | 9.3 |
213
+ | Letters lost (of 1,998) | **0** | **0** |
214
+ | Charts kept as charts (of 5) | **5** | 0 |
215
+ | One-sided borders kept as lines (of 8) | **8** | 0 |
216
+ | Fonts embedded | **Yes** | No |
217
+ | Rotated elements kept (of 5) | 3 | **5** |
218
+
219
+ dom-to-pptx also dropped the full-slide background photo on one slide. Our two rotation misses
220
+ are badges rotated inside a line of text, listed under Known gaps.
221
+
222
+ To rerun it yourself (needs Docker):
223
+
224
+ ```sh
225
+ benchmark/run.sh # html-to-native-pptx only
226
+ benchmark/run.sh --tools html-to-native-pptx,dom-to-pptx # with dom-to-pptx too
227
+ ```
228
+
229
+ Results go to `benchmark/out/results.md`. dom-to-pptx is installed and run only inside the
230
+ container.
231
+
232
+ ## Development
233
+
234
+ Everything that needs a browser or LibreOffice runs in Docker so it is the same everywhere:
235
+
236
+ ```sh
237
+ docker/dev.sh pytest -q # tests (a Chromium is required for the end-to-end ones)
238
+ uv run ruff check . && uv run ruff format --check . && uv run mypy
239
+ ```
240
+
241
+ ## Licence
242
+
243
+ MIT, copyright hollee-tom. Fonts in `corpus/fonts/` are SIL OFL 1.1 (licences alongside).
@@ -0,0 +1,221 @@
1
+ # html-to-native-pptx
2
+
3
+ **High-fidelity HTML to native, editable PowerPoint.**
4
+
5
+ html-to-native-pptx opens a deck of HTML slides in Chromium, measures what the browser actually drew, and
6
+ writes a `.pptx` whose contents are real PowerPoint objects:
7
+
8
+ - **Text** stays text: text boxes with runs, fonts, sizes, colours, letter-spacing, bullets,
9
+ links, super/subscript, and inline chips and marked words as run highlights.
10
+ - **Tables** stay tables: native tables with merged cells, fills and per-side borders.
11
+ - **Shapes** stay shapes: rectangles, rounded rectangles, ellipses and lines, with fill, outline,
12
+ opacity and rotation.
13
+ - **Charts** stay charts: figures that follow a small markup format become native PowerPoint
14
+ charts with editable data ([format](docs/charts.md)).
15
+ - **Pictures are only a fallback**, for what PowerPoint cannot express (a gradient, an SVG, a
16
+ photograph, a `::before` decoration). Each is a transparent picture of just that element,
17
+ placed *behind* the native text, so the text on top is still yours to edit.
18
+
19
+ It is not a slide-screenshot exporter: a deck made of one picture per slide is not "native".
20
+
21
+ ## Quick start
22
+
23
+ ```sh
24
+ pip install html-to-native-pptx
25
+ playwright install chromium
26
+ html-to-native-pptx deck.html -o deck.pptx
27
+ ```
28
+
29
+ ```python
30
+ from pathlib import Path
31
+ from html_to_native_pptx import convert
32
+
33
+ convert(Path("deck.html"), Path("deck.pptx"), slide_selector="section", width=1280, height=720)
34
+ ```
35
+
36
+ `html` may be a `Path` to a file, or a string of markup (pass `base_dir=` so its relative links
37
+ resolve). Every element matching `slide_selector` is one slide of `width` x `height` CSS pixels.
38
+
39
+ ```text
40
+ html-to-native-pptx deck.html -o deck.pptx
41
+ -s, --slide-selector SELECTOR CSS selector of one slide (default: section)
42
+ --width / --height PX slide size in CSS pixels (default: 1280x720)
43
+ --no-embed-fonts name fonts only; do not embed them
44
+ --no-freeze-animations measure animations as they stand
45
+ --chromium PATH a Chromium binary to drive (or set HTML_TO_NATIVE_PPTX_CHROMIUM)
46
+ --timeout SECONDS how long to wait on the page (default: 60)
47
+ ```
48
+
49
+ `html_to_native_pptx.measure(...)` returns the measurements (a pydantic `MeasuredDeck`) without writing a
50
+ file, and `html_to_native_pptx.deck_pptx(deck)` writes one from measurements, with no browser needed.
51
+
52
+ ## How it works
53
+
54
+ 1. **Measure in the browser.** Playwright loads the page as a browser does (scripts run, images
55
+ and fonts load from wherever they point). A script walks each slide's DOM and records, from
56
+ computed styles and layout, every text run, table, chart, shape and picture, in slide pixels.
57
+ 2. **Capture pictures.** Each element PowerPoint cannot express is screenshot on its own with
58
+ everything else hidden, over a transparent background. Elements with a background image or
59
+ gradient are shot with their text made clear, so the text can stay native on top.
60
+ 3. **Write natively.** python-pptx writes the objects at the measured positions. Small, targeted
61
+ XML edits cover what it lacks: alpha, highlights, the "No Style, No Grid" table style,
62
+ explicit no-line cell sides, and embedded fonts.
63
+
64
+ Code layout: `pages.py` (loading), `assets/measure.js` (the in-browser measurer),
65
+ `measurer.py` (drives it and takes the pictures), `model.py` (the measured-deck contract),
66
+ `fontfiles.py` and `fonts.py` (font discovery and embedding), `writer/` (one module each for
67
+ text, shapes, tables, charts, pictures, plus colour and units), `convert.py` and `cli.py`.
68
+
69
+ ### What it gets right that others often don't
70
+
71
+ - **See-through colours.** A faint tint behind text stays a faint tint, and an element's
72
+ `opacity` carries through, because PowerPoint has no group opacity of its own.
73
+ - **Borders on some sides.** A rule above a card stays a rule. It isn't drawn as a box around
74
+ the whole card.
75
+ - **Badges and highlighted words** keep their background, including in table cells, and the
76
+ paragraph stays one editable paragraph.
77
+ - **Spacing between inline pieces.** "01" and "Agenda" set apart with margin stay apart.
78
+ - **Content in empty-looking wrappers.** A wrapper with no height of its own, whose children are
79
+ positioned freely, still has its children exported.
80
+ - **No surprise styling from PowerPoint.** Shapes don't pick up the theme's shadow, and tables
81
+ don't pick up PowerPoint's default grid lines.
82
+ - **Odd input doesn't break the file.** A chart with no rows is skipped, and an absurd `colspan`
83
+ is capped.
84
+
85
+ ## Fonts
86
+
87
+ By default, the fonts your page uses are embedded in the `.pptx`. The slides then look right
88
+ on a computer that doesn't have those fonts installed. Turn this off with `--no-embed-fonts`.
89
+
90
+ - **It uses the fonts your page loaded**, wherever they came from: a font service such as
91
+ Google Fonts, a CDN, or local files. There's nothing to configure.
92
+ - **Each piece of text gets the exact font file the browser used**, named the way PowerPoint
93
+ expects. For example, a 300 weight becomes "Inter Light", so PowerPoint finds it.
94
+ - **Variable fonts work.** Many viewers draw a variable font at its default weight, which is
95
+ often the boldest. So each weight your slides use is saved as its own fixed font.
96
+ - **Font licences are respected.** A font that doesn't allow embedding is named in the file but
97
+ not included.
98
+ - **Not yet checked in PowerPoint.** Embedded fonts have been verified in LibreOffice. PowerPoint,
99
+ Keynote and Google Slides haven't been tested yet.
100
+
101
+ ## Supported CSS and markup
102
+
103
+ Text: font family, size, weight, style, colour, `letter-spacing`, `text-transform`,
104
+ `text-align`, `line-height`, underline, strike-through, `vertical-align: super/sub`, links,
105
+ `<br>`, `<ul>`/`<ol>` with nesting, blockquotes and `<cite>`. Inline elements with a background,
106
+ margin, padding or border become highlights and gaps. Gradient-clipped text
107
+ (`background-clip: text`) stays editable.
108
+
109
+ Boxes: background colour (with alpha), border (all sides, or per side), `border-radius`, `opacity`
110
+ (own and inherited), 2D `transform: rotate()` and scale, absolutely positioned and zero-height
111
+ wrappers, flex and grid layouts (anything the browser lays out is measured where it landed),
112
+ full-slide background images and translucent overlays. `data-shape="ellipse|line|rect"` hints a
113
+ plain shape.
114
+
115
+ Tables: `colspan`, `rowspan`, cell fills, per-side borders, vertical alignment, captions.
116
+
117
+ Charts: `figure[data-chart]` with a `table[data-chart-data]`, see [docs/charts.md](docs/charts.md).
118
+
119
+ Pictures (fallback): `<img>`, inline `<svg>`, elements with `background-image` or a gradient,
120
+ and elements with `::before`/`::after` content.
121
+
122
+ ## Known gaps
123
+
124
+ - **Inline rotated badges.** A rotated `inline-block` inside a line of text is flattened into the
125
+ paragraph: its rotation and border are lost (a rotated *block* is fine).
126
+ - **Dashed and dotted borders** are drawn solid.
127
+ - **Box shadows** are not drawn.
128
+ - **Pseudo-elements that paint outside their element's box** are clipped to the box when
129
+ pictured.
130
+ - **Hyperlinks** take the presentation theme's link colour in PowerPoint and LibreOffice, not the
131
+ CSS colour.
132
+ - **Gradient-clipped text** is editable, but the gradient lives in the picture behind it and the
133
+ native text on top is clear; edited text does not change the picture.
134
+ - **Pictures are 1x** device pixels, so a pictured photograph is as sharp as the page showed it.
135
+ - **3D transforms, filters, `mix-blend-mode`, `clip-path`** are not represented.
136
+ - **Line breaks can differ** where PowerPoint's text layout differs from the browser's; text
137
+ that the browser set on one line is kept on one line.
138
+ - **PowerPoint itself is untested**; see Fonts and the benchmark notes.
139
+
140
+ ## Benchmark
141
+
142
+ We compared html-to-native-pptx with four other open-source HTML-to-PowerPoint converters on 193
143
+ real slides, then on a public test deck anyone can rerun.
144
+
145
+ **What it shows**
146
+
147
+ - **Closest to the original.** Its slides look the most like the HTML of the five tools.
148
+ - **No lost text.** It kept every word. The other tools lost or ran together 60 to 408 words.
149
+ - **Most stays editable.** Tables stay real PowerPoint tables, borders stay lines, and charts stay
150
+ charts. Other tools turn some of these into pictures or plain text.
151
+ - **Your fonts come with the file.** It embeds the deck's own fonts, so slides look right on a
152
+ computer that doesn't have them installed.
153
+
154
+ **How much to trust it**
155
+
156
+ - The slides were checked by opening them in LibreOffice, not PowerPoint. PowerPoint may wrap a
157
+ line or space a letter slightly differently. We haven't yet tested opening the files in
158
+ PowerPoint, Keynote or Google Slides.
159
+ - The 193 real slides all came from one product's decks. HTML written another way may use CSS
160
+ these decks don't, so check your own slides.
161
+ - Each tool was run once. Small differences, about half a point on the visual score, are noise.
162
+
163
+ ### On 193 real slides
164
+
165
+ These are 8 private decks, so only the totals are published.
166
+
167
+ | | **html-to-native-pptx** | dom-to-pptx | SlideSmith | html-to-pptx | html-to-editable-pptx |
168
+ |---|---|---|---|---|---|
169
+ | Visual difference from the HTML (lower is better) | **5.2** | 6.2 | 7.3 | 7.4 | 8.2 |
170
+ | Slides that look clearly different | **3** | **3** | 10 | 4 | 12 |
171
+ | Words lost or run together (of 24,508) | **0** | 90 | 90 | 146 | 558 |
172
+ | Tables kept as tables (of 116) | **116** | **116** | **116** | 0 | 0 |
173
+ | Parts turned into pictures (fewer is more editable) | **184** | 359 | 359 | **184** | **184** |
174
+ | Letter-spacing kept | **100%** | **100%** | **100%** | 97% | 97% |
175
+ | See-through colours kept | **99%** | **99%** | **99%** | 0% | 0% |
176
+ | Rotated elements kept | 96% | **100%** | 96% | **100%** | 91% |
177
+
178
+ The visual difference is the average grey-level difference per pixel between the HTML and the
179
+ PowerPoint slide, on a 0 to 255 scale. A slide counts as clearly different above 15.
180
+
181
+ ### On the public test deck
182
+
183
+ `corpus/deck.html` is 21 slides of original HTML, built to recreate the hard cases found in real
184
+ decks: badges and highlights, see-through colours, rotation, letter-spacing, one-sided borders,
185
+ gradient headings, photo backgrounds with overlays, charts and web fonts. Its fonts are openly
186
+ licensed and their licences are in `corpus/fonts/`.
187
+
188
+ | | **html-to-native-pptx** | dom-to-pptx |
189
+ |---|---|---|
190
+ | Visual difference from the HTML (lower is better) | **4.6** | 9.3 |
191
+ | Letters lost (of 1,998) | **0** | **0** |
192
+ | Charts kept as charts (of 5) | **5** | 0 |
193
+ | One-sided borders kept as lines (of 8) | **8** | 0 |
194
+ | Fonts embedded | **Yes** | No |
195
+ | Rotated elements kept (of 5) | 3 | **5** |
196
+
197
+ dom-to-pptx also dropped the full-slide background photo on one slide. Our two rotation misses
198
+ are badges rotated inside a line of text, listed under Known gaps.
199
+
200
+ To rerun it yourself (needs Docker):
201
+
202
+ ```sh
203
+ benchmark/run.sh # html-to-native-pptx only
204
+ benchmark/run.sh --tools html-to-native-pptx,dom-to-pptx # with dom-to-pptx too
205
+ ```
206
+
207
+ Results go to `benchmark/out/results.md`. dom-to-pptx is installed and run only inside the
208
+ container.
209
+
210
+ ## Development
211
+
212
+ Everything that needs a browser or LibreOffice runs in Docker so it is the same everywhere:
213
+
214
+ ```sh
215
+ docker/dev.sh pytest -q # tests (a Chromium is required for the end-to-end ones)
216
+ uv run ruff check . && uv run ruff format --check . && uv run mypy
217
+ ```
218
+
219
+ ## Licence
220
+
221
+ MIT, copyright hollee-tom. Fonts in `corpus/fonts/` are SIL OFL 1.1 (licences alongside).
@@ -0,0 +1,50 @@
1
+ """Runs the open-source dom-to-pptx on the same HTML, so the scorers can compare it.
2
+
3
+ dom-to-pptx is a browser library: it is injected into the page and exports the slide elements.
4
+ Its code is third-party and untrusted, so this adapter runs only inside the benchmark's Docker
5
+ container, where `npm install dom-to-pptx` has put it under NODE_PATH's `node_modules`.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import base64
11
+ import os
12
+ import sys
13
+ from pathlib import Path
14
+
15
+ from playwright.sync_api import sync_playwright
16
+
17
+ BUNDLE = (
18
+ Path(os.environ.get("DOM_TO_PPTX_DIR", "/opt/dom-to-pptx"))
19
+ / "node_modules/dom-to-pptx/dist/dom-to-pptx.bundle.js"
20
+ )
21
+ EXPORT = """async (options) => {
22
+ const slides = [...document.querySelectorAll(options.selector)];
23
+ const blob = await window.domToPptx.exportToPptx(slides, { skipDownload: true, fileName: "x.pptx", width: options.width / 96, height: options.height / 96 });
24
+ const bytes = new Uint8Array(await blob.arrayBuffer());
25
+ let text = "";
26
+ for (let i = 0; i < bytes.length; i += 0x8000) text += String.fromCharCode.apply(null, bytes.subarray(i, i + 0x8000));
27
+ return btoa(text);
28
+ }"""
29
+
30
+
31
+ def main(html: str, out: str, selector: str, width: int, height: int) -> None:
32
+ """Export `html`'s slides with dom-to-pptx into `out`."""
33
+ with sync_playwright() as playwright:
34
+ browser = playwright.chromium.launch(
35
+ executable_path=os.environ.get("HTML_TO_NATIVE_PPTX_CHROMIUM")
36
+ )
37
+ page = browser.new_page(viewport={"width": width, "height": height})
38
+ page.goto(Path(html).resolve().as_uri(), wait_until="load")
39
+ page.evaluate("document.fonts.ready.then(() => true)")
40
+ page.add_script_tag(path=str(BUNDLE))
41
+ Path(out).write_bytes(
42
+ base64.b64decode(
43
+ page.evaluate(EXPORT, {"selector": selector, "width": width, "height": height})
44
+ )
45
+ )
46
+ browser.close()
47
+
48
+
49
+ if __name__ == "__main__":
50
+ main(sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4]), int(sys.argv[5]))