(json_data)
| 7 | sys.exit(1) |
| 8 | |
| 9 | def JSONtoPDF(json_data): |
| 10 | # Get the data values from the JSON string json_data. |
| 11 | try: |
| 12 | data = json.loads(json_data) |
| 13 | pdf_filename = data['pdf_filename'] |
| 14 | font_name = data['font_name'] |
| 15 | font_size = data['font_size'] |
| 16 | header = data['header'] |
| 17 | footer = data['footer'] |
| 18 | lines = data['lines'] |
| 19 | except Exception as e: |
| 20 | error_exit("Invalid JSON data: {}".format(e.message)) |
| 21 | # Generate the PDF using the data values. |
| 22 | try: |
| 23 | with PDFWriter(pdf_filename) as pw: |
| 24 | pw.setFont(font_name, font_size) |
| 25 | pw.setHeader(header) |
| 26 | pw.setFooter(footer) |
| 27 | for line in lines: |
| 28 | pw.writeLine(line) |
| 29 | except IOError as ioe: |
| 30 | error_exit("IOError while generating PDF file: {}".format(ioe.message)) |
| 31 | except Exception as e: |
| 32 | error_exit("Error while generating PDF file: {}".format(e.message)) |
| 33 | |
| 34 | def testJSONtoPDF(): |
| 35 | fil = open('the-man-in-the-arena.txt') |
no test coverage detected