示例#1
0
    def test_column_line_break(self):
        def draw_with_clip(index):
            with self.pdf.saved_state():
                self.pdf.clip_rect(-1, -5, 196, 50)
                self.pdf.translate(index * -190, 0)
                c.draw(self.pdf)

        c = DrawObjectColumn()
        c.bottom_margin = 10
        c.add_draw_object(HorizontalRuler(length=800))
        c.add_draw_object(HorizontalSegmentedLine(lengths=400 * [2]))
        with self.file_path(path, 'column_line_break', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            number_of_rows = int(ceil(c.get_width() / 190))
            for index in range(number_of_rows):
                if index != 0:
                    self.pdf.translate(0, c.get_height())
                draw_with_clip(index)
            self.pdf.write(pdf_path)
示例#2
0
    def test_column_page_break(self):
        self.pdf.t_margin = 15

        def _prepare_page():
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('v')
            self.pdf.draw_ruler('h')
            self.pdf.translate(clip_area_left_margin, clip_area_top_margin)

        def _add_page():
            self.pdf.add_page()
            _prepare_page()

        def draw_with_clip(index):
            with self.pdf.saved_state():
                self.pdf.clip_rect(-1, -5, clip_area_width + 1.14,
                                   clip_area_height)
                self.pdf.translate(index * -clip_area_width, 0)
                c.draw(self.pdf)

        c = DrawObjectColumn()
        c.bottom_margin = 60
        c.add_draw_object(HorizontalRuler(length=1200, bottom_margin=5))
        c.add_draw_object(HorizontalSegmentedLine(lengths=600 * [2]))

        clip_area_left_margin = 10
        clip_area_top_margin = 10
        clip_area_width = self.pdf.w - self.pdf.l_margin - self.pdf.r_margin - clip_area_left_margin
        clip_area_height = c.get_height()

        with self.file_path(path, 'column_page_break', 'pdf') as pdf_path:
            _prepare_page()
            number_of_rows = int(ceil(c.get_width() / clip_area_width))
            for index in range(number_of_rows):
                if index != 0:
                    self.pdf.translate(0, c.get_height())
                if self.pdf.absolute_y > self.pdf.h - self.pdf.b_margin:
                    _add_page()
                draw_with_clip(index)
            self.pdf.write(pdf_path)