mgbam commited on
Commit
da2c28a
·
verified ·
1 Parent(s): e338885

Update utils/pdf_export.py

Browse files
Files changed (1) hide show
  1. utils/pdf_export.py +19 -0
utils/pdf_export.py CHANGED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # genesis/utils/pdf_export.py
2
+ from reportlab.lib.pagesizes import letter
3
+ from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
4
+ from reportlab.lib.styles import getSampleStyleSheet
5
+ import os
6
+
7
+ def export_to_pdf(content: str, filename: str = "output.pdf"):
8
+ """Export given text content to a PDF file."""
9
+ filepath = os.path.join(os.getcwd(), filename)
10
+ doc = SimpleDocTemplate(filepath, pagesize=letter)
11
+ styles = getSampleStyleSheet()
12
+ story = []
13
+
14
+ for line in content.split("\n"):
15
+ story.append(Paragraph(line, styles["Normal"]))
16
+ story.append(Spacer(1, 12))
17
+
18
+ doc.build(story)
19
+ return filepath