fix(convert): make PDF→PPTX produce editable slides#39
Merged
Conversation
…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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
User report: ao converter PDF→PPTX, os slides ficam como uma única imagem, não como texto editável.
The previous
_convert_pptxrasterised 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:type=1) →slide.shapes.add_pictureat the block's bbox (so scanned/image-only PDFs still work).type=0) →slide.shapes.add_textboxat 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).paragraph.text = ""leaves behind).PDF and PowerPoint both use top-left origin so no Y flip; PDF points → EMU is
× 12700.Test plan
🤖 Generated with Claude Code