Think I’ve finally got something working, and it didn’t need any PDF complications.
Changed the type to “text/html”, so that I could use standard page breaks every 66 lines, as stated in my initial post. To insert those page breaks, and not leave trailing blank pages (Edge does not optimize them away), I used the following code:
lines = get_open_form().label_report_contents.text.split('\r\n')
while (lines and lines[-1] == ''): # remove trailing blank lines
lines.pop()
num_lines = len(lines)
pages = []
for group in xrange(0, num_lines, LINES_PER_PAGE):
page = '\r\n'.join(lines[group:group+LINES_PER_PAGE])
pages.append('<pre style="font-size:9px">' + page + '</pre>')
self.call_js('printPage',
'<p style="page-break-before: always">'.join(pages)
)
My lines end in \r\n
(instead of \n
) to accommodate downloading by Windows users.
EDIT: added font size setting, in case the user’s browser is set to print at 100% scale, instead of “Shrink to fit”.