My issue is that when using reportlab to generate a simple text document it loses all of the formatting. I've run it through a few times to try and debug it and the issue seems to be, when passing the msgStr
to Paragraph
it loses all of the formatting sent with it.
Does anyone know how to generate a simple pdf whilst maintaining the current text formatting
Code:
# PDF GENERATION LIBRARIES
# import the report lab PDF generation tools
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
Parts = []
def sumFile(msgStr = None, COMPLETE = 0):
pdfmetrics.registerFont(TTFont('Inconsolata', 'Inconsolata-Regular.ttf'))
summaryName = SimpleDocTemplate(vehID+".pdf")
style = ParagraphStyle(
name='Normal',
fontName='Inconsolata',
fontSize=8,
)
msgStr.replace('\n','<br />')
if msgStr == "PageBreak":
parts.append(PageBreak())
else:
parts.append(msgStr)
if COMPLETE == 1:
genStr = "Generated using " + progName + " " + str(progVers)
parts.append(genStr)
print parts
summaryName.build(Paragraph(parts, style))
if __name__ == "__main__":
sumFile("%9s %s\n" % ("Bobby", "Sue"))
sumFile("{0:12}{1:7}{2:5}deg_C\tsmp {3}\n".format("20", "1000", "3.0", "535"))
sumFile("{0} {1}\n\n".format("09/06/2016", "11:51:39"))