tag:blogger.com,1999:blog-6692866151143183230.post3807995673606581755..comments2024-03-19T16:22:18.277+05:30Comments on jugad2 - Vasudev Ram on software innovation: Control break report to PDF with xtopdfVasudev Ramhttp://www.blogger.com/profile/13568740634188042591noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-6692866151143183230.post-7838031099345862772016-07-24T22:34:43.697+05:302016-07-24T22:34:43.697+05:30Referring to the above comment, on further thought...Referring to the above comment, on further thought, I realized that I had implemented something roughly equivalent to a custom state machine (spread across multiple methods in the PDFWriter class), in the core xtopdf library in PDFWriter.py (see the xtopdf source code at the Bitbucket link in the post above). That's what takes care of the pagination, printing header and footer at the right time and place (in the PDF), page numbering, resetting font (a quirk required by ReportLab), etc. And also realized that the core xtopdf logic itself is conceptually similar to the logic of a control-break report. So, the above program, ControlBreakToPDF.py, sort of implements a control-break inside a control-break - ha ha.Vasudev Ramhttps://www.blogger.com/profile/13568740634188042591noreply@blogger.comtag:blogger.com,1999:blog-6692866151143183230.post-7862682151302928622016-07-24T03:39:06.316+05:302016-07-24T03:39:06.316+05:30While googling for links about the control break c...While googling for links about the control break concept for this post, I came across this Python recipe on ActiveState, which uses an interesting approach, a state machine:<br /><br /><a href="http://code.activestate.com/recipes/473847-control-break-report-generation-example/" rel="nofollow">Control break report generation example (Python recipe)</a><br /><br />Had not seen that approach before, though, with hindsight, it does seem like a state machine can be appropriate for this, since the program can be thought of as transitioning through several states, such as a) the initial state before any data is read, b) the state after reading the first record, and then c) one of 3 other possible states: c.1) next record read has same key as previous, c.2) next record read has different key from previous (a state change to a different key group - this is what is called a control break, from which the report gets its name), and c.3) no next record (end of data).Vasudev Ramhttps://www.blogger.com/profile/13568740634188042591noreply@blogger.com