#!/usr/bin/env python3 import argparse import os import pdfkit import popplerqt5 def collect_annotations(source): doc = popplerqt5.Poppler.Document.load(source) annotations = {} for i in range(doc.numPages()): annotations[i] = [] for annot in doc.page(i).annotations(): annotations[i].append(annot) return annotations def generate_pdf(annotations, destination="annotations.pdf", pagesize="A4"): options = { 'page-size': pagesize, 'encoding': "utf-8", 'margin-top': '0.75in', 'margin-right': '0.75in', 'margin-bottom': '0.75in', 'margin-left': '0.75in', } blocks = """
""" pages = list(annotations.keys()) pages.sort() for page in pages: for annotation in annotations[page]: content = annotation.contents() if not content: continue author = annotation.author() if author != "": header = f"Page: {page + 1} | Author: {author}" else: header = f"Page: {page + 1}" blocks += f"""