diff --git a/soitool/codebook_to_pdf.py b/soitool/codebook_to_pdf.py index 15a2edb1d45b0de7423a08d082ba8db807851f14..1e5ea38669c16b6262e675ff1bed32be58183b53 100644 --- a/soitool/codebook_to_pdf.py +++ b/soitool/codebook_to_pdf.py @@ -17,7 +17,7 @@ from reportlab.lib.units import cm from soitool.database import Database from soitool.enumerates import CodebookSort -A4_WIDTH = A4[0] +A4_WIDTH, A4_HEIGHT = A4 TITLE_FULL_CODE = "<u>Kodebok</u>" TITLE_FULL_DECODE = "<u>Dekodebok</u>" @@ -86,14 +86,14 @@ def generate_codebook_pdf(small=False, page_size=A4, orientation=portrait): # Add title, vertical spacer and table for codebook elements = [] elements.append(title_code) - elements.append(Spacer(1, 1 * cm)) + elements.append(Spacer(0, 1 * cm)) elements.append(table_code) elements.append(PageBreak()) # Add blank page to separate code- and decodebook elements.append(PageBreak()) # Add title, vertical spacer and table for decodebook elements.append(title_decode) - elements.append(Spacer(1, 1 * cm)) + elements.append(Spacer(0, 1 * cm)) elements.append(table_decode) # Generate filename @@ -179,15 +179,21 @@ class CodeAndDecodebookDocTemplate(SimpleDocTemplate): If code- and decodebook use 10 pages each, the total page count will be 20, but this class will draw 'Side 1 av 10' through 'Side 10 av 10' for both. - 'Side x av y' is not drawn on blank pages. + The first blank page (2 * Pagebreak) added will be marked as a separating + page, and will not contain 'Side x av y'. """ + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.pagebreak_counter = 0 + def afterFlowable(self, flowable): - """Reset pagenumber and don't write pagecount on blank page.""" + """Reset pagenumber and mark blank first page as separating page.""" # If flowable is a Paragraph, - # it is the title on the first page of decodebook. + # it is the title on the first page of code- or decodebook if isinstance(flowable, Paragraph): - # Save startpage-number to get correct total, individual pagecount. + # Save startpage-number to get correct total, individual pagecount self.canv.decodebook_startpage = self.canv.getPageNumber() - 1 # Reset page number @@ -195,10 +201,42 @@ class CodeAndDecodebookDocTemplate(SimpleDocTemplate): self.canv.draw_page_count = True if isinstance(flowable, PageBreak): + self.pagebreak_counter += 1 + + # Mark first blank page + if self.pagebreak_counter == 1: + self.mark_separating_page() + self.canv.draw_page_count = False super().afterFlowable(flowable) + def mark_separating_page(self): + """Mark the page separating code- and decodebook. + + Put solid, black squares in each corner and centered text + stating that the page is for separation only. + """ + # Draw solid squares in each corner + self.canv.rect( + 0, A4_HEIGHT - 2.8 * cm, 80, 80, fill=True, + ) + self.canv.rect( + A4_WIDTH - 2.8 * cm, A4_HEIGHT - 2.8 * cm, 80, 80, fill=True, + ) + self.canv.rect( + 0, 0, 80, 80, fill=True, + ) + self.canv.rect( + A4_WIDTH - 2.8 * cm, 0, 80, 80, fill=True, + ) + # Draw centered text + text = "SKILLESIDE" + text_width = self.canv.stringWidth(text) + self.canv.drawString( + A4_WIDTH / 2 - text_width / 2, A4_HEIGHT / 2, text + ) + # pylint: disable=W0223 # Disabling pylint-warning 'Method is abstract in class but is not overridden'.