Exemple #1
0
    def build(self, flowables, onFirstPage=_doNothing, onLaterPages=_doNothing, canvasmaker=canvas.Canvas):
        """build the document using the flowables.  Annotate the first page using the onFirstPage
               function and later pages using the onLaterPages function.  The onXXX pages should follow
               the signature

                  def myOnFirstPage(canvas, document):
                      # do annotations and modify the document
                      ...

               The functions can do things like draw logos, page numbers,
               footers, etcetera. They can use external variables to vary
               the look (for example providing page numbering or section names).
        """
        self._calc()  # in case we changed margins sizes etc
        frameT = Frame(self.leftMargin, self.bottomMargin, self.width, self.height, id="normal")
        self.addPageTemplates(
            [
                PageTemplate(id="First", frames=frameT, onPage=onFirstPage, pagesize=self.pagesize),
                PageTemplate(id="Later", frames=frameT, onPage=onLaterPages, pagesize=self.pagesize),
            ]
        )
        if onFirstPage is _doNothing and hasattr(self, "onFirstPage"):
            self.pageTemplates[0].beforeDrawPage = self.onFirstPage
        if onLaterPages is _doNothing and hasattr(self, "onLaterPages"):
            self.pageTemplates[1].beforeDrawPage = self.onLaterPages
        BaseDocTemplate.build(self, flowables, canvasmaker=canvasmaker)
Exemple #2
0
 def __init__(self, filename, **kw):
     self.allowSplitting = 0
     BaseDocTemplate.__init__(self, filename, **kw)
     template = PageTemplate(
         "normal", [Frame(2.5 * cm, 2.5 * cm, 15 * cm, 25 * cm, id="F1")]
     )
     self.addPageTemplates(template)
Exemple #3
0
    def __init__(self, filename, context, **kw):
        BaseDocTemplate.__init__(self, filename, **kw)
        self.toc_index = 0
        self.main_frame_attr = {'x1': self.leftMargin,
                                'y1': self.bottomMargin,
                                'width': self.width,
                                'height': self.height,
                                'id':'normal',
                                'showBoundary': self.showBoundary}

        # We keep the main frame reference to resize it during the build
        self.main_frame = Frame(**self.main_frame_attr)
        self.main_frame_change = False
        template_attrs = {'id': 'now', 'frames': [self.main_frame],
                          'pagesize': kw['pagesize']}
        page_template = PageTemplate(**template_attrs)
        self.platypus_header_calculate = False
        self.platypus_header_height = None
        self.platypus_footer = None
        self.context = context
        self.addPageTemplates([page_template])
        self.toc_high_level = self.context.toc_high_level

        self.frame_attr = {'leftPadding': 0, 'bottomPadding': 6,
                           'rightPadding': 0, 'topPadding': 6,
                           'showBoundary': 0}
        self.context = context
        # calculate width available
        self.width_available = self.width
        self.width_available -= self.frame_attr['leftPadding']
        self.width_available -= self.frame_attr['rightPadding']
 def __init__(self, filename, **kw):
     self.allowSplitting = 0
     kw["showBoundary"] = 1
     BaseDocTemplate.__init__(self, filename, **kw)
     self.addPageTemplates(
         [
             PageTemplate(
                 "normal",
                 [
                     Frame(
                         inch,
                         inch,
                         6.27 * inch,
                         9.69 * inch,
                         id="first",
                         topPadding=0,
                         rightPadding=0,
                         leftPadding=0,
                         bottomPadding=0,
                         showBoundary=ShowBoundaryValue(color="red"),
                     )
                 ],
             )
         ]
     )
Exemple #5
0
    def __init__(self, filename, **kw):
        self.allowSplitting = 0

        self.pagesize = kw.get('pagesize', landscape(A5))
        kw['pagesize'] = self.pagesize

        BaseDocTemplate.__init__(self, filename, **kw)

        w, h = self.pagesize

        # self.actualWidth, self.actualHeight = landscape(A5)
        self.topMargin = 2.85 * cm
        self.leftMargin = 0.15 * cm
        self.bottomMargin = 0.15 * cm

        fh = h - self.topMargin - self.bottomMargin
        fw = w - (2 * self.leftMargin)

        frame = Frame(self.leftMargin,
                      self.bottomMargin,
                      fw,
                      fh,
                      id='ContentFrame',
                      showBoundary=False)

        template = PageTemplate('normal',
                                frames=[
                                    frame,
                                ],
                                pagesize=self.pagesize)
        self.loadFonts()
        self.addPageTemplates(template)
    def __init__(self, filename, **kw):
        m = 2 * cm
        from reportlab.lib import pagesizes

        PAGESIZE = pagesizes.landscape(pagesizes.A4)
        cw, ch = (PAGESIZE[0] - 2 * m) / 2.0, (PAGESIZE[1] - 2 * m)
        ch -= 14 * cm
        f1 = Frame(
            m,
            m + 0.5 * cm,
            cw - 0.75 * cm,
            ch - 1 * cm,
            id="F1",
            leftPadding=0,
            topPadding=0,
            rightPadding=0,
            bottomPadding=0,
            showBoundary=True,
        )
        f2 = Frame(
            cw + 2.7 * cm,
            m + 0.5 * cm,
            cw - 0.75 * cm,
            ch - 1 * cm,
            id="F2",
            leftPadding=0,
            topPadding=0,
            rightPadding=0,
            bottomPadding=0,
            showBoundary=True,
        )
        BaseDocTemplate.__init__(self, filename, **kw)
        template = PageTemplate("template", [f1, f2])
        self.addPageTemplates(template)
Exemple #7
0
 def __init__(self, filename, **kw):
     self.allowSplitting = 0
     BaseDocTemplate.__init__(self, filename, **kw)
     template = PageTemplate('normal', [Frame(2.5*cm, 2.5*cm, 15*cm, 25*cm, id='F1')])
     self.addPageTemplates(template)
     def afterFlowable(self, flowable):
         "Registers TOC entries."
Exemple #8
0
    def __init__(self, filename, **kw):

        self.allowSplitting = 0
        BaseDocTemplate.__init__(self, filename, **kw)

        self.pagesize = A4
        self.topMargin = 0.5 * cm
        self.bottomMargin = 2 * cm
        self.leftMargin = 1 * cm
        self.rightMargin = 1 * cm
        self._calc()

        frameT = Frame(self.leftMargin,
                       self.bottomMargin,
                       self.width,
                       self.height,
                       id='normal',
                       showBoundary=0)
        # Table of contents padding
        tocP = 3 * cm
        frameTOC = Frame(self.leftMargin,
                         self.bottomMargin,
                         self.width,
                         self.height,
                         leftPadding=tocP,
                         rightPadding=tocP,
                         id='toc',
                         showBoundary=0)

        titleTemplate = PageTemplate('title', frames=frameT, onPage=titlePage)
        tocTemplate = PageTemplate('toc', frames=frameTOC, onPage=tocPage)
        template = PageTemplate('normal', frames=frameT, onPage=defaultPage)

        self.addPageTemplates([titleTemplate, tocTemplate, template])
Exemple #9
0
    def __init__(self, filename, **kw):
        self.allowSplitting = 0

        self.pagesize = kw.get('pagesize', landscape(A5))
        kw['pagesize'] = self.pagesize

        BaseDocTemplate.__init__(self, filename, **kw)

        w, h = self.pagesize

        # self.actualWidth, self.actualHeight = landscape(A5)
        self.topMargin = 2.85 * cm
        self.leftMargin = 0.15 * cm
        self.bottomMargin = 0.15 * cm

        fh = h - self.topMargin - self.bottomMargin
        fw = w - (2 * self.leftMargin)

        frame = Frame(self.leftMargin, self.bottomMargin,
                      fw, fh,
                      id='ContentFrame',
                      showBoundary=False)

        template = PageTemplate('normal', frames=[frame, ],
                                pagesize=self.pagesize)
        self.loadFonts()
        self.addPageTemplates(template)
Exemple #10
0
    def __init__(self, filename, context, **kw):
        BaseDocTemplate.__init__(self, filename, **kw)
        self.toc_index = 0
        body_attrs = (self.leftMargin, self.bottomMargin, self.width,
                      self.height)
        self.main_frame_attr = {'x1': self.leftMargin,
                                'y1': self.bottomMargin,
                                'width': self.width,
                                'height': self.height,
                                'id':'normal',
                                'showBoundary': self.showBoundary}

        # We keep the main frame reference to resize it during the build
        self.main_frame = Frame(**self.main_frame_attr)
        self.main_frame_change = False
        template_attrs = {'id': 'now', 'frames': [self.main_frame],
                          'pagesize': kw['pagesize']}
        page_template = PageTemplate(**template_attrs)
        self.platypus_header_calculate = False
        self.platypus_header_height = None
        self.platypus_footer = None
        self.context = context
        self.addPageTemplates([page_template])
        self.toc_high_level = self.context.toc_high_level

        self.frame_attr = {'leftPadding': 0, 'bottomPadding': 6,
                           'rightPadding': 0, 'topPadding': 6,
                           'showBoundary': 0}
        self.context = context
        # calculate width available
        self.width_available = self.width
        self.width_available -= self.frame_attr['leftPadding']
        self.width_available -= self.frame_attr['rightPadding']
    def __init__(self, filename, plugin_dir, growing_year, cur_date, **kw):
        """Generate a basic A4 pdf document

        Parameters
        ----------
        filename: str
            The file name to store the PDF document
        tr: translation
            The Translation function from GeoDataFarm
        plugin_dir: str
            path to the plugin dir in order to find the icon
        growing_year: int
             What growing year
        cur_date: str
            Current date, to write on the report
        kw
        """
        BaseDocTemplate.__init__(self, filename, **kw)
        self.allowSplitting = 1
        translate = TR('MyDocTemplate')
        self.tr = translate.tr
        self.plugin_dir = plugin_dir
        frame = Frame(self.leftMargin,
                      self.bottomMargin,
                      self.width,
                      self.height - 2 * cm,
                      id='normal')
        template = PageTemplate(id='test',
                                frames=frame,
                                onPage=partial(self.header,
                                               growing_year=growing_year,
                                               cur_date=cur_date))
        self.addPageTemplates(template)
 def __init__(self, filename, **kw):
     m = 2 * cm
     from reportlab.lib import pagesizes
     PAGESIZE = pagesizes.landscape(pagesizes.A4)
     cw, ch = (PAGESIZE[0] - 2 * m) / 2., (PAGESIZE[1] - 2 * m)
     ch -= 14 * cm
     f1 = Frame(m,
                m + 0.5 * cm,
                cw - 0.75 * cm,
                ch - 1 * cm,
                id='F1',
                leftPadding=0,
                topPadding=0,
                rightPadding=0,
                bottomPadding=0,
                showBoundary=True)
     f2 = Frame(cw + 2.7 * cm,
                m + 0.5 * cm,
                cw - 0.75 * cm,
                ch - 1 * cm,
                id='F2',
                leftPadding=0,
                topPadding=0,
                rightPadding=0,
                bottomPadding=0,
                showBoundary=True)
     BaseDocTemplate.__init__(self, filename, **kw)
     template = PageTemplate('template', [f1, f2])
     self.addPageTemplates(template)
Exemple #13
0
 def test5(self):
     '''extreme test inspired by Moritz Pfeiffer https://bitbucket.org/moritzpfeiffer/'''
     with self.assertRaises(LayoutError):
         text="""
         Clearly, the natural general principle that will subsume this case is
         not subject to a parasitic gap construction.  Presumably, most of the
         methodological work in modern linguistics can be defined in such a way
         as to impose the system of base rules exclusive of the lexicon.  In the
         discussion of resumptive pronouns following (81), the fundamental error
         of regarding functional notions as categorial is to be regarded as a
         descriptive <span color="red">fact</span>.<br/>So far, the earlier discussion of deviance is not
         quite equivalent to a parasitic gap construction.  To characterize a
         linguistic level L, a case of semigrammaticalness of a different sort
         may remedy and, at the same time, eliminate irrelevant intervening
         contexts in selectional <span color="red">rules</span>.<br/>
         Summarizing, then, we assume that the descriptive power of the base
         component can be defined in such a way as to impose nondistinctness in
         the sense of distinctive feature theory.
         """
         styleSheet = getSampleStyleSheet()
         story = []
         story.append(Paragraph(text, styleSheet['Normal']))
         doc = BaseDocTemplate(
             outputfile('test_platypus_much_too_large.pdf'),
             pagesize=portrait(A4),
             pageTemplates=[PageTemplate(
                 'page_template',
                 [Frame(0, 0, 0, 0, leftPadding=0, rightPadding=0, topPadding=0, bottomPadding=0, id='DUMMY_FRAME')],
                 )],
             )
         doc.build(story)
 def __init__(self, filename, **kw):
     frame1 = Frame(2.5*cm, 2.5*cm, 16*cm, 25*cm, id='F1')
     self.allowSplitting = 0
     BaseDocTemplate.__init__(self, filename, **kw)
     template = PageTemplate('nomal', [frame1], onPageEnd=HeaderFooter)
     #template = PageTemplate('nomal', [Frame(2.5*cm, 2.5*cm, 16*cm, 25*cm, id='F1')], onPageEnd=HeaderFooter)
     #template = PageTemplate('nomal', [Frame(2.5*cm, 2.5*cm, 16*cm, 25*cm, id='F1', showBoundary=1)], onPageEnd=HeaderFooter)
     self.addPageTemplates(template)
 def __init__(self, filename, **kw):
     frame1 = Frame(2.5*cm, 2.5*cm, 15*cm, 25*cm, id='F1')
     frame2 = Frame(2.5*cm, 2.5*cm, 310, 25*cm, id='F2')
     self.allowSplitting = 0
     BaseDocTemplate.__init__(self, filename, **kw)
     template = PageTemplate('normal', [frame1], myMainPageFrame)
     template1 = PageTemplate('special', [frame2], myMainPageFrame)
     self.addPageTemplates([template,template1])
Exemple #16
0
 def __init__(self, filename, **kw):
     self.allowSplitting = 0
     BaseDocTemplate.__init__(self, filename, **kw)
     self.page_width, self.page_height = self.pagesize
     first_page_tpl = PageTemplate(
         'normal', [Frame(0, 0, 21 * cm, 29.7 * cm, id='F1')],
         onPage=self._draw_static_elements)
     self.addPageTemplates(first_page_tpl)
 def __init__(self, filename, **kw):
     frame1 = Frame(2.5*cm, 2.5*cm, 15*cm, 25*cm, id='F1')
     frame2 = Frame(2.5*cm, 2.5*cm, 310, 25*cm, id='F2')
     self.allowSplitting = 0
     BaseDocTemplate.__init__(self, filename, **kw)
     template = PageTemplate('normal', [frame1], myMainPageFrame)
     template1 = PageTemplate('special', [frame2], myMainPageFrame)
     self.addPageTemplates([template,template1])
Exemple #18
0
def export(listino, luogoDiRiferimento):
    response = http.HttpResponse(content_type='application/pdf')
    width, height = portrait(A4)

    pageTemplates = [
        PageTemplate(id='Listino', onPage=onPageListino),
    ]

    doc = BaseDocTemplate(
        response,
        pagesize=(width, height),
        leftMargin=1 * cm,
        rightMargin=1 * cm,
        bottomMargin=1.5 * cm,
        topMargin=1 * cm,
        showBoundary=test,
        pageTemplates=pageTemplates,
    )

    doc.listino = listino  # arricchisco il doc

    righe_prezzo = listino.prezzolistino_set.all()

    story = []

    listinoEsclusivo = getTabellaListino(doc, righe_prezzo, 'T', luogoDiRiferimento)
    if listinoEsclusivo:
        title = Paragraph("SERVIZIO TAXI ESCLUSIVO", normalStyle)
        story.append(title)
        story.append(listinoEsclusivo)

    listinoCollettivo = getTabellaListino(doc, righe_prezzo, 'C', luogoDiRiferimento)
    if listinoEsclusivo and listinoCollettivo:
        story.append(Spacer(1, 1.5 * cm))
    if listinoCollettivo:
        title = Paragraph("SEVIZIO COLLETIVO MINIBUS", normalStyle)
        story.append(KeepTogether([title, listinoCollettivo]))

    if not listinoCollettivo and not listinoEsclusivo:
        story.append(
            Paragraph("Non abbiamo nessuna corsa specificata nel listino.", normal_style)
        )

    # footer
    footer_style = ParagraphStyle(name='Justify', alignment=TA_JUSTIFY, fontSize=8)
    # footer_height = 0
    if LISTINO_FOOTER:
        note_finali_lines = [LISTINO_FOOTER]
        story.append(Spacer(1, 1 * cm))
        note_finali = Paragraph("<br/>".join(note_finali_lines),
                                footer_style)
        # note_finali.wrap(width - doc.rightMargin - doc.leftMargin, 5 * cm)
        # note_finali.drawOn(canvas, doc.leftMargin, doc.bottomMargin)
        # footer_height = note_finali.height
        story.append(note_finali)

    doc.build(story, canvasmaker=NumberedCanvas)
    return response
 def __init__(self, filename, **kw):
     BaseDocTemplate.__init__(self, filename, **kw)
     self.addPageTemplates(
         [
             PageTemplate(id="plain", frames=[Frame(2.5 * cm, 2.5 * cm, 16 * cm, 25 * cm, id="F1")]),
             LeftPageTemplate(),
             RightPageTemplate(),
         ]
     )
 def __init__(self, filename, **kw):
     self.allowSplitting = 0
     BaseDocTemplate.__init__(self, filename, **kw)
     self.addPageTemplates(
             [
             PageTemplate('normal',
                     [Frame(inch, inch, 6.27*inch, 9.69*inch, id='first',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red"))],
                     ),
             ])
Exemple #21
0
 def __init__(self, filename, **kw):
     BaseDocTemplate.__init__(self, filename, **kw)
     self.addPageTemplates([
         PageTemplate(
             id='plain',
             frames=[Frame(2.5 * cm, 2.5 * cm, 16 * cm, 25 * cm, id='F1')]),
         LeftPageTemplate(),
         RightPageTemplate()
     ])
 def __init__(self, filename, **kw):
     frame1 = Frame(2.5 * cm, 2.5 * cm, 15 * cm, 25 * cm, id="F1")
     frame2 = Frame(2.5 * cm, 2.5 * cm, 310, 25 * cm, id="F2")
     self.allowSplitting = 0
     BaseDocTemplate.__init__(self, filename, **kw)
     template = PageTemplate("normal", [frame1], myMainPageFrame)
     template1 = PageTemplate("special", [frame2], myMainPageFrame)
     template2 = PageTemplate("template2", [Frame(395, 108, 165, 645, id="second2")])
     self.addPageTemplates([template, template1, template2])
 def __init__(self, filename, **kw):
     self.allowSplitting = 0
     BaseDocTemplate.__init__(self, filename, **kw)
     self.addPageTemplates(
             [
             PageTemplate('normal',
                     [Frame(inch, inch, 6.27*inch, 9.69*inch, id='first',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red"))],
                     ),
             ])
Exemple #24
0
 def __init__(self, output, status_callback=None, tocCallback=None, **kwargs):
     self.bookmarks = []
     BaseDocTemplate.__init__(self, output, **kwargs)
     if status_callback:
         self.estimatedDuration = 0
         self.progress = 0
         self.setProgressCallBack(self.progressCB)
         self.status_callback = status_callback
     self.tocCallback = tocCallback
     self.title = kwargs["title"]
 def __init__(self, filename, **kw):
     frame1 = Frame(2.5*cm, 15.5*cm, 6*cm, 10*cm, id='F1')
     frame2 = Frame(11.5*cm, 15.5*cm, 6*cm, 10*cm, id='F2')
     frame3 = Frame(2.5*cm, 2.5*cm, 6*cm, 10*cm, id='F3')
     frame4 = Frame(11.5*cm, 2.5*cm, 6*cm, 10*cm, id='F4')
     self.allowSplitting = 0
     self.showBoundary = 1
     BaseDocTemplate.__init__(self, filename, **kw)
     template = PageTemplate('normal', [frame1, frame2, frame3, frame4], myMainPageFrame)
     self.addPageTemplates(template)
Exemple #26
0
    def __init__(self, filename, pagesize, stickysize, show_boundary=False):
        self.cols = int(pagesize[0] // stickysize[0])
        self.rows = int(pagesize[1] // stickysize[1])

        templates = [
            StickyPage('sticky-page', pagesize, stickysize, self.cols,
                       self.rows, show_boundary),
        ]
        BaseDocTemplate.__init__(self, filename, pageTemplates=templates,
                                 allowSplitting=0, creator=self._get_creator())
 def __init__(self, filename, **kw):
     frame1 = Frame(2.5 * cm, 15.5 * cm, 6 * cm, 10 * cm, id="F1")
     frame2 = Frame(11.5 * cm, 15.5 * cm, 6 * cm, 10 * cm, id="F2")
     frame3 = Frame(2.5 * cm, 2.5 * cm, 6 * cm, 10 * cm, id="F3")
     frame4 = Frame(11.5 * cm, 2.5 * cm, 6 * cm, 10 * cm, id="F4")
     self.allowSplitting = 0
     self.showBoundary = 1
     BaseDocTemplate.__init__(self, filename, **kw)
     template = PageTemplate("normal", [frame1, frame2, frame3, frame4], myMainPageFrame)
     self.addPageTemplates(template)
def _showDoc(fn,story):
    pageTemplate = PageTemplate('normal', [Frame(72, 440, 170, 284, id='F1'),
                            Frame(326, 440, 170, 284, id='F2'),
                            Frame(72, 72, 170, 284, id='F3'),
                            Frame(326, 72, 170, 284, id='F4'),
                            ], myMainPageFrame)
    doc = BaseDocTemplate(outputfile(fn),
            pageTemplates = pageTemplate,
            showBoundary = 1,
            )
    doc.multiBuild(story)
Exemple #29
0
 def __init__(self, filename, **kw):
     frame1 = Frame(2.5 * cm, 15.5 * cm, 6 * cm, 10 * cm, id='F1')
     frame2 = Frame(11.5 * cm, 15.5 * cm, 6 * cm, 10 * cm, id='F2')
     frame3 = Frame(2.5 * cm, 2.5 * cm, 6 * cm, 10 * cm, id='F3')
     frame4 = Frame(11.5 * cm, 2.5 * cm, 6 * cm, 10 * cm, id='F4')
     self.allowSplitting = 0
     self.showBoundary = 1
     BaseDocTemplate.__init__(self, filename, **kw)
     template = PageTemplate('normal', [frame1, frame2, frame3, frame4],
                             myMainPageFrame)
     self.addPageTemplates(template)
def _showDoc(fn,story):
    pageTemplate = PageTemplate('normal', [Frame(72, 440, 170, 284, id='F1'),
                            Frame(326, 440, 170, 284, id='F2'),
                            Frame(72, 72, 170, 284, id='F3'),
                            Frame(326, 72, 170, 284, id='F4'),
                            ], myMainPageFrame)
    doc = BaseDocTemplate(outputfile(fn),
            pageTemplates = pageTemplate,
            showBoundary = 1,
            )
    doc.multiBuild(story)
    def __init__(self, filename, **kw):
        frame1 = Frame(2.5*cm, 2.5*cm, 15*cm, 25*cm, id='F1')
        self.allowSplitting = 0
        BaseDocTemplate.__init__(self, filename, **kw)
        template1 = PageTemplate('normal', [frame1], myMainPageFrame)

        frame2 = Frame(2.5*cm, 16*cm, 15*cm, 10*cm, id='F2', showBoundary=1)
        frame3 = Frame(2.5*cm, 2.5*cm, 15*cm, 10*cm, id='F3', showBoundary=1)

        template2 = PageTemplate('updown', [frame2, frame3])
        self.addPageTemplates([template1, template2])
    def __init__(self, filename, **kw):
        frame1 = Frame(2.5 * cm, 2.5 * cm, 15 * cm, 25 * cm, id="F1")
        self.allowSplitting = 0
        BaseDocTemplate.__init__(self, filename, **kw)
        template1 = PageTemplate("normal", [frame1], myMainPageFrame)

        frame2 = Frame(2.5 * cm, 16 * cm, 15 * cm, 10 * cm, id="F2", showBoundary=1)
        frame3 = Frame(2.5 * cm, 2.5 * cm, 15 * cm, 10 * cm, id="F3", showBoundary=1)

        template2 = PageTemplate("updown", [frame2, frame3])
        self.addPageTemplates([template1, template2])
Exemple #33
0
	def multiBuild(self,flowables,onFirstPage=_doNothing, onLaterPages=_doNothing): 
		self._calc() #in case we changed margins sizes etc 
		frameFirst = Frame(2*cm, 2*cm, 17*cm, 23*cm, id='F1')
		frameLater = Frame(2.5*cm, 2*cm, 16*cm, 24.5*cm, id='F2')
		
		self.addPageTemplates([
			PageTemplate (id='First',frames=frameFirst, onPage=onFirstPage, pagesize=self.pagesize), 
			PageTemplate(id='Later',frames=frameLater, onPage=onLaterPages, pagesize=self.pagesize)
		]) 
		
		BaseDocTemplate.multiBuild(self,flowables) 
    def __init__(self, filename, **kw):
        frame1 = Frame(2.5*cm, 2.5*cm, 15*cm, 25*cm, id='F1')
        self.allowSplitting = 0
        BaseDocTemplate.__init__(self, filename, **kw)
        template1 = PageTemplate('normal', [frame1], myMainPageFrame)

        frame2 = Frame(2.5*cm, 16*cm, 15*cm, 10*cm, id='F2', showBoundary=1)
        frame3 = Frame(2.5*cm, 2.5*cm, 15*cm, 10*cm, id='F3', showBoundary=1)

        template2 = PageTemplate('updown', [frame2, frame3])
        self.addPageTemplates([template1, template2])
Exemple #35
0
    def __init__(self, *args, **kwargs):
        BaseDocTemplate.__init__(self, *args, **kwargs)
        self.bottomTableHeight = 0
        self.bottomTableIsLast = False
        self.numPages = 0
        self._lastNumPages = 0
        self.setProgressCallBack(self._onProgress_cb)

        # For batch reports with several PDFs concatenated
        self.restartDoc = False
        self.restartDocIndex = 0
        self.restartDocPageNumbers = []
Exemple #36
0
    def __init__(self, *args, **kwargs):
        BaseDocTemplate.__init__(self, *args, **kwargs)
        self.bottomTableHeight = 0
        self.bottomTableIsLast = False
        self.numPages = 0
        self._lastNumPages = 0
        self.setProgressCallBack(self._onProgress_cb)

        # For batch reports with several PDFs concatenated
        self.restartDoc = False
        self.restartDocIndex = 0
        self.restartDocPageNumbers = []
Exemple #37
0
    def build(self, flowables, firstPageTemplate=_doNothing, laterPageTemplate=_doNothing):
        """Custom build method to separate first page and later page templates.

        """
        self._calc() # in case we changed margin sizes

        if firstPageTemplate is _doNothing and hasattr(self, 'firstPageTemplate'):
            self.pageTemplates[0].beforeDrawPage = self.firstPageTemplate
        if laterPageTemplate is _doNothing and hasattr(self, 'laterPageTemplate'):
            self.pageTemplates[1].beforeDrawPage = self.laterPageTemplate

        BaseDocTemplate.build(self, flowables)
Exemple #38
0
    def __init__(self, filename, **kw):
        frame1 = Frame(inch, inch, A4[0] - 2 * inch, A4[1] - 2 * inch, id='F1')
        self.allowSplitting = 0
        BaseDocTemplate.__init__(self, filename, **kw)
        template = PageTemplate('normal', [frame1], myMainPageFrame)
        self.addPageTemplates(template)

        top_margin = A4[1] - inch
        bottom_margin = inch
        left_margin = inch
        right_margin = A4[0] - inch
        frame_width = right_margin - left_margin
    def build(self, flowables, onFirstPage=_doNothing, canvasmaker=canvas.Canvas):
        self._calc()

        frameT = Frame(letter_left_margin, letter_bottom_margin, letter_frame_width, letter_frame_height,
                       leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0,
                       id='normal')

        self.addPageTemplates([PageTemplate(id='First',frames=frameT, onPage=onFirstPage, pagesize=self.pagesize)])

        if onFirstPage is _doNothing and hasattr(self,'onFirstPage'):
            self.pageTemplates[0].beforeDrawPage = self.onFirstPage

        BaseDocTemplate.build(self, flowables, canvasmaker=canvasmaker)
def _showDoc(fn, story):
    pageTemplate = PageTemplate(
        "normal",
        [
            Frame(72, 440, 170, 284, id="F1"),
            Frame(326, 440, 170, 284, id="F2"),
            Frame(72, 72, 170, 284, id="F3"),
            Frame(326, 72, 170, 284, id="F4"),
        ],
        myMainPageFrame,
    )
    doc = BaseDocTemplate(outputfile(fn), pageTemplates=pageTemplate, showBoundary=1)
    doc.multiBuild(story)
Exemple #41
0
def renderElements(elements, filesuffix=None, tmpdir=None):
    """ takes a list of reportlab flowables and renders them to a test.pdf file"""
    margin = 2 * cm
    if filesuffix:
        fn = 'test_' + filesuffix + '.pdf'
    else:
        fn = 'test.pdf'
    fn = os.path.join(tmpdir, fn)
    doc = BaseDocTemplate(fn, topMargin=margin, leftMargin=margin, rightMargin=margin, bottomMargin=margin)
    pt = WikiPage("Title")
    doc.addPageTemplates(pt)
    elements.insert(0, NextPageTemplate('Title'))   
    doc.build(elements)
Exemple #42
0
 def __init__(self,
              output,
              status_callback=None,
              tocCallback=None,
              **kwargs):
     self.bookmarks = []
     BaseDocTemplate.__init__(self, output, **kwargs)
     if status_callback:
         self.estimatedDuration = 0
         self.progress = 0
         self.setProgressCallBack(self.progressCB)
         self.status_callback = status_callback
     self.tocCallback = tocCallback
     self.title = kwargs['title']
Exemple #43
0
 def build(self, flowables):
     self._calc()  #in case we changed margins sizes etc
     frameT = Frame(self.leftMargin,
                    self.bottomMargin,
                    self.width,
                    self.height,
                    id='normal',
                    leftPadding=0,
                    bottomPadding=0,
                    rightPadding=0,
                    topPadding=0)
     self.addPageTemplates(
         [PageTemplate(id='First', frames=frameT, pagesize=self.pagesize)])
     BaseDocTemplate.build(self, flowables, canvasmaker=self._canvasMaker)
 def __init__(self, filename, **kw):
     BaseDocTemplate.__init__(self, filename, **kw)
     template = PageTemplate('normal', [
         Frame(0,
               0,
               A4[0],
               A4[1],
               leftPadding=31.8 * mm,
               bottomPadding=25.4 * mm,
               rightPadding=31.8 * mm,
               topPadding=25.4 * mm)
     ],
                             onPageEnd=self.footer)
     # 定义页面模版,页脚可有可无
     self.addPageTemplates(template)  # 加入页面模版
Exemple #45
0
    def _startBuild(self, filename=None, canvasmaker=canvas.Canvas):
        BaseDocTemplate._startBuild(self, filename=filename, canvasmaker=canvasmaker)

        type2lvl = {"chapter": 0, "article": 1, "heading2": 2, "heading3": 3, "heading4": 4}
        got_chapter = False
        last_lvl = 0
        for (bm_id, (bm_title, bm_type)) in enumerate(self.bookmarks):
            lvl = type2lvl[bm_type]
            if bm_type == "chapter":
                got_chapter = True
            elif not got_chapter:  # outline-lvls can't start above zero
                lvl -= 1
            lvl = min(lvl, last_lvl + 1)
            last_lvl = lvl
            self.canv.addOutlineEntry(bm_title, str(bm_id), lvl, bm_type == "article")
 def __init__(self, filename, **kw):
     self.allowSplitting = 0
     BaseDocTemplate.__init__(self, filename, **kw)
     frameT = Frame(self.leftMargin,
                    self.bottomMargin,
                    self.width,
                    self.height,
                    id='F1')
     template_title_page = PageTemplate('title_page',
                                        frames=frameT,
                                        onPage=title_page)
     template_later_pages = PageTemplate('later_pages',
                                         frames=frameT,
                                         onPage=later_pages)
     self.addPageTemplates(template_title_page)
     self.addPageTemplates(template_later_pages)
Exemple #47
0
 def _allSatisfied(self):
     status = BaseDocTemplate._allSatisfied(self)
     if self.context.current_page != self.context.number_of_pages:
         status = 0
     self.context.number_of_pages = self.context.current_page
     self.context.current_page = 0
     self.toc_index = 0
     return status
Exemple #48
0
 def _allSatisfied(self):
     status = BaseDocTemplate._allSatisfied(self)
     if self.context.current_page != self.context.number_of_pages:
         status = 0
     self.context.number_of_pages = self.context.current_page
     self.context.current_page = 0
     self.toc_index = 0
     return status
Exemple #49
0
 def test5(self):
     '''extreme test inspired by Moritz Pfeiffer https://bitbucket.org/moritzpfeiffer/'''
     with self.assertRaises(LayoutError):
         text = """
         Clearly, the natural general principle that will subsume this case is
         not subject to a parasitic gap construction.  Presumably, most of the
         methodological work in modern linguistics can be defined in such a way
         as to impose the system of base rules exclusive of the lexicon.  In the
         discussion of resumptive pronouns following (81), the fundamental error
         of regarding functional notions as categorial is to be regarded as a
         descriptive <span color="red">fact</span>.<br/>So far, the earlier discussion of deviance is not
         quite equivalent to a parasitic gap construction.  To characterize a
         linguistic level L, a case of semigrammaticalness of a different sort
         may remedy and, at the same time, eliminate irrelevant intervening
         contexts in selectional <span color="red">rules</span>.<br/>
         Summarizing, then, we assume that the descriptive power of the base
         component can be defined in such a way as to impose nondistinctness in
         the sense of distinctive feature theory.
         """
         styleSheet = getSampleStyleSheet()
         story = []
         story.append(Paragraph(text, styleSheet['Normal']))
         doc = BaseDocTemplate(
             outputfile('test_platypus_much_too_large.pdf'),
             pagesize=portrait(A4),
             pageTemplates=[
                 PageTemplate(
                     'page_template',
                     [
                         Frame(0,
                               0,
                               0,
                               0,
                               leftPadding=0,
                               rightPadding=0,
                               topPadding=0,
                               bottomPadding=0,
                               id='DUMMY_FRAME')
                     ],
                 )
             ],
         )
         doc.build(story)
    def __init__(self,
                 dictValeurs={},
                 dictOptions={},
                 IDmodele=None,
                 ouverture=True,
                 nomFichier=None):
        """ Impression """
        global DICT_VALEURS, DICT_OPTIONS
        DICT_VALEURS = dictValeurs
        DICT_OPTIONS = dictOptions

        # Initialisation du document
        if nomFichier == None:
            nomDoc = FonctionsPerso.GenerationNomDoc("LOCATIONS", "pdf")
        else:
            nomDoc = nomFichier
        doc = BaseDocTemplate(nomDoc, pagesize=TAILLE_PAGE, showBoundary=False)

        # Mémorise le ID du modèle
        modeleDoc = DLG_Noedoc.ModeleDoc(IDmodele=IDmodele)
        doc.modeleDoc = modeleDoc

        # Importe le template de la première page
        doc.addPageTemplates(MyPageTemplate(pageSize=TAILLE_PAGE, doc=doc))

        story = []
        styleSheet = getSampleStyleSheet()
        h3 = styleSheet['Heading3']
        styleTexte = styleSheet['BodyText']
        styleTexte.fontName = "Helvetica"
        styleTexte.fontSize = 9
        styleTexte.borderPadding = 9
        styleTexte.leading = 12

        # ----------- Insertion du contenu des frames --------------
        listeLabels = []
        for IDlocation, dictValeur in dictValeurs.iteritems():
            listeLabels.append((dictValeur["{FAMILLE_NOM}"], IDlocation))
        listeLabels.sort()

        for labelDoc, IDlocation in listeLabels:
            dictValeur = dictValeurs[IDlocation]
            if dictValeur["select"] == True:

                story.append(DocAssign("IDlocation", IDlocation))
                nomSansCivilite = dictValeur["{FAMILLE_NOM}"]
                story.append(Bookmark(nomSansCivilite, str(IDlocation)))

                # Saut de page
                story.append(PageBreak())

        # Finalisation du PDF
        doc.build(story)

        # Ouverture du PDF
        if ouverture == True:
            FonctionsPerso.LanceFichierExterne(nomDoc)
Exemple #51
0
def pdf_basic_page( objects, title='', preferences=None ): # used by gen_table.make_page()
    """Simple convenience fonction: build a page from a list of platypus objects,
    adding a title if specified.
    """
    StyleSheet = styles.getSampleStyleSheet()
    report = cStringIO.StringIO() # in-memory document, no disk file
    document = BaseDocTemplate(report)
    document.addPageTemplates(
        ScolarsPageTemplate(document,
                            title=title,
                            author='%s %s (E. Viennet)' % (SCONAME, SCOVERSION),
                            footer_template="Edité par %(scodoc_name)s le %(day)s/%(month)s/%(year)s à %(hour)sh%(minute)s",
                            preferences=preferences
                            ))
    if title:
        head = Paragraph(SU(title), StyleSheet["Heading3"])
        objects = [ head ] + objects
    document.build(objects)
    data = report.getvalue()
    return data
Exemple #52
0
    def multiBuild(self,
                   flowables,
                   onFirstPage=_doNothing,
                   onLaterPages=_doNothing):
        self._calc()  #in case we changed margins sizes etc
        frameFirst = Frame(2 * cm, 2 * cm, 17 * cm, 23 * cm, id='F1')
        frameLater = Frame(2.5 * cm, 2 * cm, 16 * cm, 24.5 * cm, id='F2')

        self.addPageTemplates([
            PageTemplate(id='First',
                         frames=frameFirst,
                         onPage=onFirstPage,
                         pagesize=self.pagesize),
            PageTemplate(id='Later',
                         frames=frameLater,
                         onPage=onLaterPages,
                         pagesize=self.pagesize)
        ])

        BaseDocTemplate.multiBuild(self, flowables)
Exemple #53
0
    def __init__(self, filename, cfgparser, **kw):
        self.allowSplitting = 0
        # Inch graph size (width, height)
        self.graph_size = (float(cfgparser.get("page", "graph_width")),
                           float(cfgparser.get("page", "graph_height")))
        self.x_axis = ('Time', 12, '%m-%d %H:%M', 20)
        self.tablestyle = [
            ('ROWBACKGROUNDS', (0, 0), (-1, -1), (colors.lightgrey, colors.white)),
            ('GRID', (0, 0), (-1, -1), 1, colors.toColor(cfgparser.get("string_table", "color"))),
            ('ALIGN', (0, 0), (-1, -1), cfgparser.get("string_table", "align")),
            ('LEFTPADDING', (0, 0), (-1, -1), int(cfgparser.get("string_table", "leftPadding"))),
            ('RIGHTPADDING', (0, 0), (-1, -1), int(cfgparser.get("string_table", "rightPadding"))),
            ('FONTSIZE', (0, 0), (-1, -1), int(cfgparser.get("string_table", "fontSize"))),
            ('FONTNAME', (0, 0), (-1, 0), cfgparser.get("string_table", "font")), ]
        BaseDocTemplate.__init__(self, filename, **kw)
        template = PageTemplate('normal', [Frame(
            float(cfgparser.get("page", "x1")) * inch,
            float(cfgparser.get("page", "y1")) * inch,
            float(cfgparser.get("page", "width")) * inch,
            float(cfgparser.get("page", "height")) * inch,
            id='F1')])
        self.addPageTemplates(template)

        font_list = ["centered", "centered_index", "small_centered",
                     "heading1", "heading1_centered", "heading1_invisible",
                     "heading2", "heading2_centered", "heading2_invisible",
                     "mono", "mono_centered", "normal", "front_title", "axes"]
        int_fields = ["fontSize", "leading", "alignment", "spaceAfter"]
        self.fonts = {}
        for font in font_list:
            sheet = getSampleStyleSheet()
            text = sheet['BodyText']
            section = "font_%s" % font
            items = dict(cfgparser.items(section))
            for i in int_fields:
                if i in items:
                    items[i] = int(items[i])

            tmp_ps = PS(font, parent=text)
            tmp_ps.__dict__.update(items)
            self.fonts[font] = tmp_ps
Exemple #54
0
 def __init__(self, name, study_name):
     self.doc = BaseDocTemplate(name,
                                title=name,
                                showBoundary=0,
                                pagesize=letter)
     template = PageTemplate('normal',
                             [Frame(inch, inch, 6.5 * inch, 8.4 * inch)],
                             onPageEnd=self.pageHeader)
     self.doc.addPageTemplates(template)
     #self.doc.setProgressCallBack(self.progressCB)
     self.styles = stylesheet()
     self.jobsize = 1
     self.headerId = 0
     self.headerVisitLabel = ''
     self.headerPlateLabel = ''
     self.studyName = study_name
     self.outlines = []
     self.outlineDesc = None
     self.outlineVisitLabel = None
     self.outlineID = 0
     self.content = [DFOutlines(self.outlines)]
    def build(self,flowables,onFirstPage=_doNothing, onLaterPages=_doNothing, canvasmaker=canvas.Canvas):
        """build the document using the flowables.  Annotate the first page using the onFirstPage
               function and later pages using the onLaterPages function.  The onXXX pages should follow
               the signature

                  def myOnFirstPage(canvas, document):
                      # do annotations and modify the document
                      ...

               The functions can do things like draw logos, page numbers,
               footers, etcetera. They can use external variables to vary
               the look (for example providing page numbering or section names).
        """
        self._calc()    #in case we changed margins sizes etc
        frameT = Frame(self.leftMargin, self.bottomMargin, self.width, self.height, id='normal')
        self.addPageTemplates([PageTemplate(id='First',frames=frameT, onPage=onFirstPage,pagesize=self.pagesize),
                        PageTemplate(id='Later',frames=frameT, onPage=onLaterPages,pagesize=self.pagesize)])
        if onFirstPage is _doNothing and hasattr(self,'onFirstPage'):
            self.pageTemplates[0].beforeDrawPage = self.onFirstPage
        if onLaterPages is _doNothing and hasattr(self,'onLaterPages'):
            self.pageTemplates[1].beforeDrawPage = self.onLaterPages
        BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
Exemple #56
0
def pagecat2(request):
    doc = BaseDocTemplate('test.pdf')
    frame_title = Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-6, doc.height, id='title')
    frame_back = Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-6, doc.height, id='back')
    frame_1col = Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-6, doc.height, id='col12')
    frame1_2col = Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-6, doc.height, id='col1')
    frame2_2col = Frame(doc.leftMargin+doc.width/2+6, doc.bottomMargin, doc.width/2-6, doc.height, id='col2')

    doc.addPageTemplates([
        PageTemplate(id='Title', frames=frame_title, onPage=static_title),
        PageTemplate(id='Back', frames=frame_back, onPage=static_back),
        PageTemplate(id='OneCol', frames=frame_1col, onPage=static_1col),
        PageTemplate(id='TwoCol', frames=[frame1_2col, frame2_2col], onPage=static_2col),
    ])
    story = [Paragraph('<b>Table of contents</b>', ParagraphStyle('normal')),
             NextPageTemplate('TwoCol'),
             PageBreak(),
             '<includePdfPages filename="pdf1.pdf" pages="1,2,3"/>',
             NextPageTemplate('TwoCol')]

    doc.build(story)
    return render(request, "test.html")
Exemple #57
0
    def __init__(self, filename, **kw):
        frame1 = Frame(2.5 * cm, 2.5 * cm, 15 * cm, 25 * cm, id='F1')
        self.allowSplitting = 0
        BaseDocTemplate.__init__(self, filename, **kw)
        template1 = PageTemplate('normal', [frame1], myMainPageFrame)

        frame2 = Frame(2.5 * cm,
                       16 * cm,
                       15 * cm,
                       10 * cm,
                       id='F2',
                       showBoundary=1)
        frame3 = Frame(2.5 * cm,
                       2.5 * cm,
                       15 * cm,
                       10 * cm,
                       id='F3',
                       showBoundary=1)

        greenBoundary = ShowBoundaryValue(color=toColor('darkgreen'),
                                          width=0.5)
        templateX = PageTemplate('templateX', [
            Frame(3 * cm,
                  7.5 * cm,
                  14 * cm,
                  4 * cm,
                  id='XF4',
                  showBoundary=greenBoundary),
            Frame(3 * cm,
                  2.5 * cm,
                  14 * cm,
                  4 * cm,
                  id='XF5',
                  showBoundary=greenBoundary)
        ])

        template2 = PageTemplate('updown', [frame2, frame3])
        self.addPageTemplates([template1, template2, templateX])
Exemple #58
0
 def __init__(self,
              filename,
              sprint=None,
              logo_orange=None,
              logo_phoenix=None,
              team_img=None,
              **kw):
     self.allowSplitting = 0
     self.sprint = sprint
     self.name_report = split(filename)[1]
     self.logo_orange = logo_orange
     self.logo_phoenix = logo_phoenix
     self.team_img = team_img
     self.orangeColor = colors.Color(1, 0.47, 0)
     self.styles = getSampleStyleSheet()
     self.styles.add(
         ParagraphStyle(name='TitlePage',
                        parent=self.styles['Normal'],
                        fontSize=32,
                        textColor=self.orangeColor))
     self.styles.add(
         ParagraphStyle(name='Link',
                        parent=self.styles['Normal'],
                        textColor=self.orangeColor))
     BaseDocTemplate.__init__(self, filename, **kw)
     frame = Frame(self.leftMargin,
                   self.bottomMargin,
                   self.width,
                   self.height,
                   id='normal')
     self.addPageTemplates([
         PageTemplate(id='First',
                      frames=frame,
                      onPage=lambda c, d: self.first_page(c)),
         PageTemplate(id='OneCol',
                      frames=frame,
                      onPageEnd=lambda c, d: self.foot_page(c)),
     ])
Exemple #59
0
    def _startBuild(self, filename=None, canvasmaker=canvas.Canvas):
        BaseDocTemplate._startBuild(self,
                                    filename=filename,
                                    canvasmaker=canvasmaker)

        type2lvl = {
            'chapter': 0,
            'article': 1,
            'heading2': 2,
            'heading3': 3,
            'heading4': 4,
        }
        got_chapter = False
        last_lvl = 0
        for (bm_id, (bm_title, bm_type)) in enumerate(self.bookmarks):
            lvl = type2lvl[bm_type]
            if bm_type == 'chapter':
                got_chapter = True
            elif not got_chapter:  # outline-lvls can't start above zero
                lvl -= 1
            lvl = min(lvl, last_lvl + 1)
            last_lvl = lvl
            self.canv.addOutlineEntry(bm_title, str(bm_id), lvl,
                                      bm_type == 'article')