-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_source2.py
34 lines (28 loc) · 912 Bytes
/
print_source2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import inch
import cgi
import tempfile
import win32api
source_file_name = "d:/1.txt"
source_file_name = "d:/UNH-IOL_NVMe_Interop_Test_Suite_v9.0.pdf"
pdf_file_name = tempfile.mktemp(".pdf")
styles = getSampleStyleSheet()
h1 = styles["h1"]
normal = styles["Normal"]
doc = SimpleDocTemplate(pdf_file_name)
#
# reportlab expects to see XML-compliant
# data; need to escape ampersands &c.
#
text = cgi.escape(open(source_file_name).read()).splitlines()
#
# Take the first line of the document as a
# header; the rest are treated as body text.
#
story = [Paragraph(text[0], h1)]
for line in text[1:]:
story.append(Paragraph(line, normal))
story.append(Spacer(1, 0.2 * inch))
doc.build(story)
win32api.ShellExecute(0, "print", pdf_file_name, None, ".", 0)