Create PDF from scratch - write strings to PDF in Python. Fore reference and credits please visit: http://com.puter.tips/2016/12/create-pdf-from-python.html
import io | |
from reportlab.platypus import SimpleDocTemplate, Paragraph | |
from reportlab.lib.styles import getSampleStyleSheet | |
from reportlab.lib.units import inch | |
from reportlab.lib.pagesizes import letter | |
buf = io.BytesIO() | |
doc = SimpleDocTemplate( | |
buf, | |
rightMargin=inch/2, | |
leftMargin=inch/2, | |
topMargin=inch/2, | |
bottomMargin=inch/2, | |
pagesize=letter, | |
) | |
styles = getSampleStyleSheet() | |
paragraphs = [] | |
paragraphs.append(Paragraph('This is first line', styles['Normal'])) | |
paragraphs.append(Paragraph('This is last line', styles['Normal'])) | |
doc.build(paragraphs) | |
with open('demo.pdf', 'wb') as fd: | |
fd.write(buf.getvalue()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment