Skip to content

Instantly share code, notes, and snippets.

@mayanez
Created May 9, 2020 00:14
Show Gist options
  • Save mayanez/e83cbd8e341d1b9a922a474903230f1d to your computer and use it in GitHub Desktop.
Save mayanez/e83cbd8e341d1b9a922a474903230f1d to your computer and use it in GitHub Desktop.
pptx2pdf-annotate
"""
Adds PPTX Presenter Notes as PDF Text Annotations.
This can then be used with `pdfpc` (https://github.com/pdfpc/pdfpc) for presentations.
NOTE:
<input.pptx> and <input.pdf> must contain the same number of pages.
"""
import sys
from pptx import Presentation
from pdf_annotate import PdfAnnotator, Location, Appearance
if len(sys.argv) <= 3:
print('Usage: pptx2pdf-annot.py <input.pptx> <input.pdf> <output.pdf>')
sys.exit(1)
prs = Presentation(sys.argv[1])
pdf = PdfAnnotator(sys.argv[2])
output = sys.argv[3]
for page, slide in enumerate(prs.slides):
if slide.has_notes_slide:
notes_slide = slide.notes_slide
note_text = notes_slide.notes_text_frame.text
# NOTE: pdf_annotate library currently doesn't support UTF-8
encoded_text = note_text.encode('latin-1', 'ignore').decode()
pdf.add_annotation('text', Location(x1=0, y1=0, x2=0, y2=0, page=page),
Appearance(
fill=[0, 0, 1, 0.5],
wrap_text=True,
content=str(encoded_text)
))
pdf.write(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment