Skip to content

Instantly share code, notes, and snippets.

@mayanez
Created May 9, 2020 00:14

Revisions

  1. mayanez created this gist May 9, 2020.
    36 changes: 36 additions & 0 deletions pptx2pdf-annotate.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    """
    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)