aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xannotation-summary.py39
-rw-r--r--annotation-summary.spec4
2 files changed, 28 insertions, 15 deletions
diff --git a/annotation-summary.py b/annotation-summary.py
index 969874b..42ddd7c 100755
--- a/annotation-summary.py
+++ b/annotation-summary.py
@@ -5,8 +5,8 @@ import os
import pdfkit
import popplerqt5
-def extract(fn, show=False):
- doc = popplerqt5.Poppler.Document.load(fn)
+def collect_annotations(source):
+ doc = popplerqt5.Poppler.Document.load(source)
annotations = {}
for i in range(doc.numPages()):
annotations[i] = []
@@ -16,19 +16,32 @@ def extract(fn, show=False):
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',
- }
+ 'page-size': pagesize,
+ 'encoding': "utf-8",
+ 'margin-top': '0.75in',
+ 'margin-right': '0.75in',
+ 'margin-bottom': '0.75in',
+ 'margin-left': '0.75in',
+ }
blocks = """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
+ <style>
+ <!--
+ .annotation {
+ border: 1px solid #300;
+ padding: 10px;
+ display: block !important;
+ page-break-inside: avoid !important;
+ }
+ .content {
+ white-space: pre-wrap;
+ }
+ -->
+ </style>
</head>
<body>
"""
@@ -46,10 +59,10 @@ def generate_pdf(annotations, destination="annotations.pdf", pagesize="A4"):
else:
header = f"<span>Page: {page + 1}</span>"
blocks += f"""
- <div style="border: 1px solid #300;">
+ <div class="annotation">
{header}<br/>
<hr/>
- <div style="white-space: pre-wrap;">{content}</div>
+ <div class="content">{content}</div>
</div>
<br/>
"""
@@ -67,5 +80,5 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('source')
args = parser.parse_args()
- annotations = extract(args.source, show=True)
- generate_pdf(annotations)
+ annotation_list = collect_annotations(args.source)
+ generate_pdf(annotation_list)
diff --git a/annotation-summary.spec b/annotation-summary.spec
index 54d9ffd..72ef40a 100644
--- a/annotation-summary.spec
+++ b/annotation-summary.spec
@@ -1,10 +1,10 @@
-%global commit 84754fefd8ccfff11137b016a2c80d3c2f5ea217
+%global commit 4eb9008f6e5a954b1f523915fee470c2b91ba01f
%global shortcommit %(c=%{commit}; echo ${c:0:7})
%global snapinfo 20200206git%{shortcommit}
Name: annotation-summary
Version: 0.1
-Release: 1.%{snapinfo}%{?dist}
+Release: 2.%{snapinfo}%{?dist}
Summary: Extract annotations/notes from a pdf file
License: undef