Skip to content

fix(convert): make PDF→PPTX produce editable slides#39

Merged
nelsonduarte merged 2 commits into
mainfrom
fix/pptx-editable-text
May 7, 2026
Merged

fix(convert): make PDF→PPTX produce editable slides#39
nelsonduarte merged 2 commits into
mainfrom
fix/pptx-editable-text

Conversation

@nelsonduarte
Copy link
Copy Markdown
Owner

Problem

User report: ao converter PDF→PPTX, os slides ficam como uma única imagem, não como texto editável.

The previous _convert_pptx rasterised each PDF page at 2× DPI and embedded the resulting PNG filling the whole slide. PowerPoint opened the file but every slide was a flat picture — no selectable / editable text.

Fix

Replace the rasterised path with a structured extraction over page.get_text("dict").blocks:

  • Image blocks (type=1) → slide.shapes.add_picture at the block's bbox (so scanned/image-only PDFs still work).
  • Text blocks (type=0) → slide.shapes.add_textbox at the block's bbox; each line becomes a paragraph; each span becomes a run carrying its own font size, bold, italic, and RGB color (extracted from PDF span attributes: size, flags & 16, flags & 2, color).
  • Internal textbox margins zeroed so the textbox bbox matches the PDF bbox more faithfully.
  • Reuse the auto-created empty run on the first paragraph for the first span; add new runs for subsequent spans (avoids the stale empty run that paragraph.text = "" leaves behind).

PDF and PowerPoint both use top-left origin so no Y flip; PDF points → EMU is × 12700.

Test plan

  • Smoke test on Ubuntu 26.04 + Py3.14.4: a 3-page PDF with a heading + two body lines per page now produces a 30 KB PPTX with 9 textframes (3 per slide) and 0 image shapes. Before the fix, the same input produced ~60 KB of rasterised PNGs per slide. Sample run output:
    [info] textframes total: 9
    [info] images total: 0
    [slide 1] ['Heading 1', 'Body paragraph on page 1.', 'Line two of the body.']
    [slide 2] ['Heading 2', 'Body paragraph on page 2.', 'Line two of the body.']
    [slide 3] ['Heading 3', 'Body paragraph on page 3.', 'Line two of the body.']
    
  • Live test in PowerPoint: convert a real text-rich PDF, verify text is selectable and editable, fonts respect bold/italic, no rasterised page background remains.
  • Live test with a scanned/image-only PDF: image blocks should still embed as picture shapes; the slide won't be editable text but at least the existing image fidelity is preserved.

🤖 Generated with Claude Code

…mages

The previous _convert_pptx rasterised each PDF page at 2× DPI and
embedded the resulting PNG covering the whole slide. The output
opened in PowerPoint but every slide was a single image — text
couldn't be selected, edited, or restyled.

Replace the rasterised path with a structured extraction:
- Iterate `page.get_text("dict")` blocks. For each block use the
  bbox to position a corresponding shape on the slide, with PDF
  points → EMU conversion (1 pt = 12700 EMU). Both PDF and PowerPoint
  use top-left origin so no Y flip is needed.
- Image blocks (type=1) are embedded as picture shapes at their
  bbox. Scanned/image-only PDFs still work — they just yield image
  shapes instead of textboxes.
- Text blocks (type=0) become textboxes. Each line is a paragraph;
  each span is a run with its own font size, bold, italic, and RGB
  color taken from PDF span attributes (size / flags & 16 / flags &
  2 / color>>16,>>8,&0xff). Internal margins are zeroed so the
  textbox bbox matches the PDF bbox more faithfully.
- Reuse the auto-created empty run on the first paragraph for the
  first span; add new runs for subsequent spans. Avoids the stale
  empty run that `paragraph.text = ""` would leave behind.

Smoke test on Ubuntu 26.04 + Py3.14.4: a 3-page PDF with a heading
and two body lines per page now produces a 30 KB PPTX with 9
textframes (3 per slide) and 0 image shapes. Before this change the
same input produced ~60 KB of rasterised PNGs per slide.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread app/tools/convert.py Fixed
Comment thread app/tools/convert.py Fixed
Comment thread app/tools/convert.py Fixed
Comment thread app/tools/convert.py Fixed
CodeQL flagged 4 'pass' clauses with no explanatory comment in the
new editable-PPTX code. Add inline comments explaining the fallback
behaviour for each (image format unsupported by python-pptx,
older-pptx margin rejection, junk PDF span size, placeholder color
rejection) and tag the one-liners with `# noqa: S110` per project
style.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@nelsonduarte nelsonduarte merged commit 4ee8cd1 into main May 7, 2026
3 checks passed
@nelsonduarte nelsonduarte deleted the fix/pptx-editable-text branch May 7, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants