946 | def writetextdoctopdf(text, **kwargs): |
947 | |
948 | output = {} |
949 | try: |
950 | import reportlab |
951 | except ImportError: |
952 | output['message'] += "You do not have reportlab installed. You need to do that. " |
953 | output['status'] = 1 |
954 | return output |
955 | |
956 | from reportlab.pdfgen import canvas |
957 | from reportlab.lib.pagesizes import letter, landscape |
958 | from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation |
959 | from reportlab.platypus import Paragraph, SimpleDocTemplate, XBox, Indenter, XPreformatted |
960 | from reportlab.lib.styles import ParagraphStyle |
961 | from reportlab.lib.units import inch |
962 | from reportlab.lib.colors import red, black, navy, white, green |
963 | from reportlab.lib.randomtext import randomText |
964 | from reportlab.rl_config import defaultPageSize |
965 | |
966 | styNormal = ParagraphStyle('normal') |
967 | |
968 | styIndent1 = ParagraphStyle('normal', leftIndent=10) |
969 | |
970 | body = [] |
971 | |
972 | for index,item in enumerate(text.split('\n')): |
973 | tabs = item.count('\t') |
974 | thisStyle = ParagraphStyle('normal', leftIndent=10*tabs) |
975 | body.append(Paragraph(item, thisStyle)) |
976 | |
977 | body.append(Paragraph("""\n\tThis has newlines and tabs on the front but inside the para tag""", styNormal)) |
978 | doc = SimpleDocTemplate(kwargs['outputfile']) |
979 | |
980 | doc.build(body) |
981 | |
982 | return output |