当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.doForm方法代码示例

本文整理汇总了Python中reportlab.pdfgen.canvas.Canvas.doForm方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.doForm方法的具体用法?Python Canvas.doForm怎么用?Python Canvas.doForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reportlab.pdfgen.canvas.Canvas的用法示例。


在下文中一共展示了Canvas.doForm方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_pdf

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import doForm [as 别名]
def make_pdf(outfn, xobjpairs):
    canvas = Canvas(outfn)
    for xobjlist in xobjpairs:
        x = y = 0
        for xobj in xobjlist:
            x += xobj.BBox[2]
            y = max(y, xobj.BBox[3])

        canvas.setPageSize((x,y))

        # Handle blank back page
        if len(xobjlist) > 1 and xobjlist[0] == xobjlist[-1]:
            xobjlist = xobjlist[:1]
            x = xobjlist[0].BBox[2]
        else:
            x = 0
        y = 0

        for xobj in xobjlist:
            canvas.saveState()
            canvas.translate(x, y)
            canvas.doForm(makerl(canvas, xobj))
            canvas.restoreState()
            x += xobj.BBox[2]
        canvas.showPage()
    canvas.save()
开发者ID:kulbirsaini,项目名称:pdfrw-fork,代码行数:28,代码来源:booklet.py

示例2: control_forms

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import doForm [as 别名]
def control_forms ( pieces, output ):
    """Write a pdf file to 'output',
    and generate control forms (one or more pages each) for 'pieces'.
    """
    c = Canvas ( output, pagesize=letter )
    pdf = PdfReader ( settings.ARTSHOW_BLANK_CONTROL_FORM )
    xobj = pagexobj ( pdf.pages[0] )
    rlobj = makerl ( c, xobj )
    for artist, piecegroup in group_pieces_by_artist_and_n ( pieces, PIECES_PER_CONTROL_FORM ):
        c.doForm ( rlobj )
        text_into_box ( c, settings.ARTSHOW_SHOW_YEAR, 2.4, 10.3, 3.05, 10.6 )
        text_into_box ( c, unicode(artist.artistid), 6.6, 10.25, 8.0, 10.5 )
        text_into_box ( c, artist.person.name, 1.7, 9.875, 4.1, 10.225, style=left_align_style )
        text_into_box ( c, artist.artistname(), 1.7, 9.5,    4.1, 9.85, style=left_align_style )
        text_into_box ( c, artist.person.address1 + " " + artist.person.address2, 1.7, 9.125,  4.1, 9.475, style=left_align_style )
        text_into_box ( c, artist.person.city, 1.7, 8.75,   4.1,  9.1, style=left_align_style   )
        text_into_box ( c, artist.person.state, 1.7, 8.375,  4.1,  8.725, style=left_align_style )
        text_into_box ( c, artist.person.postcode, 1.7, 8.0,    4.1,  8.35, style=left_align_style  )
        text_into_box ( c, artist.person.country, 1.7, 7.625,  4.1,  7.975, style=left_align_style )
        text_into_box ( c, artist.person.phone, 1.7, 7.25,   4.1,  7.6, style=left_align_style   )
        text_into_box ( c, artist.person.email, 4.9, 9.875, 8.0, 10.225, style=left_align_style, fontSize=16 )      
        text_into_box ( c, ", ".join ( [agent.person.name for agent in artist.agent_set.all()] ), 5.9, 7.625, 8.0, 7.975, style=left_align_style )
        for i, piece in enumerate(piecegroup):
            if piece is None: continue
            y0 = 6.45 - i*0.25
            y1 = 6.675 - i*0.25
            text_into_box ( c, unicode(piece.pieceid), 0.5, y0, 1.0, y1 )           
            text_into_box ( c, piece.name, 1.0, y0, 4.0, y1, style=left_align_style )           
            text_into_box ( c, yn(piece.adult), 4.0, y0, 4.5, y1 )          
            text_into_box ( c, priceornfs(piece.not_for_sale,piece.min_bid), 4.5, y0, 5.25, y1 )            
            text_into_box ( c, buynoworna(piece.buy_now), 5.25, y0, 6.0, y1 )           
        c.showPage ()
    c.save ()
开发者ID:chmarr,项目名称:artshow-fc2013,代码行数:35,代码来源:preprint.py

示例3: go

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import doForm [as 别名]
def go(inpfn, firstpage, lastpage):
    firstpage, lastpage = int(firstpage), int(lastpage)
    outfn = 'subset_%s_to_%s.%s' % (firstpage, lastpage, os.path.basename(inpfn))

    pages = PdfReader(inpfn).pages
    pages = [pagexobj(x) for x in pages[firstpage-1:lastpage]]
    canvas = Canvas(outfn)

    for page in pages:
        canvas.setPageSize(tuple(page.BBox[2:]))
        canvas.doForm(makerl(canvas, page))
        canvas.showPage()

    canvas.save()
开发者ID:lamby,项目名称:pkg-pdfrw,代码行数:16,代码来源:subset.py

示例4: encryptPdfInMemory

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import doForm [as 别名]
def encryptPdfInMemory(inputPDF,
                  userPassword, ownerPassword=None,
                  canPrint=1, canModify=1, canCopy=1, canAnnotate=1,
                       strength=40):
    """accepts a PDF file 'as a byte array in memory'; return encrypted one.

    This is a high level convenience and does not touch the hard disk in any way.
    If you are encrypting the same file over and over again, it's better to use
    pageCatcher and cache the results."""

    try:
        from rlextra.pageCatcher.pageCatcher import storeFormsInMemory, restoreFormsInMemory
    except ImportError:
        raise ImportError('''reportlab.lib.pdfencrypt.encryptPdfInMemory failed because rlextra cannot be imported.
See http://developer.reportlab.com''')

    (bboxInfo, pickledForms) = storeFormsInMemory(inputPDF, all=1, BBoxes=1)
    names = bboxInfo.keys()

    firstPageSize = bboxInfo['PageForms0'][2:]

    #now make a new PDF document
    buf = getStringIO()
    canv = Canvas(buf, pagesize=firstPageSize)

    # set a standard ID while debugging
    if CLOBBERID:
        canv._doc._ID = "[(xxxxxxxxxxxxxxxx)(xxxxxxxxxxxxxxxx)]"
    encryptCanvas(canv,
                  userPassword, ownerPassword,
                  canPrint, canModify, canCopy, canAnnotate,
                  strength=strength)

    formNames = restoreFormsInMemory(pickledForms, canv)
    for formName in formNames:
        #need to extract page size in future
        canv.doForm(formName)
        canv.showPage()
    canv.save()
    return buf.getvalue()
开发者ID:7o9,项目名称:stdm-plugin,代码行数:42,代码来源:pdfencrypt.py

示例5: grid_overlay

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import doForm [as 别名]
def grid_overlay(infile, outfile=sys.stdout, pagesize=letter, lpi=10):
    """Read PDF file 'infile'. Generates a new PDF file to 'outfile'
    containing the first page (only) of infile, with a 'lpi' grid
    overlaid.
    """

    c = Canvas(outfile, pagesize=pagesize)

    pdf = PdfReader(infile)
    xobj = pagexobj(pdf.pages[0])
    rlobj = makerl(c, xobj)

    c.doForm(rlobj)

    xmax = 9
    ymax = 12

    thickline = 0.5
    thinline = 0.1

    for x in range(0, xmax):
        c.setLineWidth(thickline)
        for xx in range(0, lpi):
            x0 = (x + (float(xx) / lpi)) * inch
            c.line(x0, 0, x0, ymax * inch)
            c.setLineWidth(thinline)

    for y in range(0, ymax):
        c.setLineWidth(thickline)
        for yy in range(0, lpi):
            y0 = (y + (float(yy) / lpi)) * inch
            c.line(0, y0, xmax * inch, y0)
            c.setLineWidth(thinline)

    c.showPage()
    c.save()
开发者ID:chmarr,项目名称:artshow-jockey,代码行数:38,代码来源:overgrid.py

示例6: bidder_agreement

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import doForm [as 别名]
def bidder_agreement(bidder, output):
    from reportlab.pdfbase import pdfmetrics
    from reportlab.pdfbase.ttfonts import TTFont

    pdfmetrics.registerFont(TTFont(*settings.ARTSHOW_BARCODE_FONT))

    c = Canvas(output, pagesize=letter)
    pdf = PdfReader(settings.ARTSHOW_BLANK_BIDDER_AGREEMENT)
    xobj = pagexobj(pdf.pages[0])
    rlobj = makerl(c, xobj)

    c.translate(0, 5.5 * inch)

    c.doForm(rlobj)
    text_into_box(c, u"*P" + unicode(bidder.person.id) + u"*", 3.5, 4.8, 5.5, 5.05, fontSize=14, style=barcode_style)
    text_into_box(c, "Ref. " + unicode(bidder.person.id), 3.5, 4.55, 5.5, 4.75, fontSize=10)

    text_into_box(c, bidder.person.reg_id, 6.2, 1.35, 7.7, 1.6, fontSize=12)

    text_into_box(c, bidder.person.name, 1.3, 1.4, 5.2, 1.7, fontSize=14)
    text_into_box(c, bidder.at_con_contact, 2.1, 0.5, 5.2, 0.8, fontSize=12)

    c.showPage()
    c.save()
开发者ID:chmarr,项目名称:artshow-fc2013,代码行数:26,代码来源:preprint.py

示例7: PdfReader

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import doForm [as 别名]
input_file = fname + ".pdf"
output_file = fname.rstrip("d") + ".pdf"

# Get pages
reader = PdfReader(input_file)
pages = [pagexobj(p) for p in reader.pages]


# Compose new pdf
canvas = Canvas(output_file)

for page_num, page in enumerate(pages, start=1):

    # Add page
    canvas.setPageSize((page.BBox[2], page.BBox[3]))
    canvas.doForm(makerl(canvas, page))

    # Draw footer
    footer_text = "Page %s of %s" % (page_num, len(pages))
    x = 128
    canvas.saveState()
    canvas.setStrokeColorRGB(0, 0, 0)
    canvas.setLineWidth(0.5)

    canvas.line(66, 53, page.BBox[2] - 66, 53)
    canvas.setFont("Times-Roman", 10)
    canvas.drawString(page.BBox[2] - x, 40, footer_text)

    canvas.restoreState()

    canvas.showPage()
开发者ID:josifoski,项目名称:twitter2pdf,代码行数:33,代码来源:twitter2pdf.py

示例8: bid_sheets

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import doForm [as 别名]
def bid_sheets ( pieces, output ):

    from reportlab.pdfbase import pdfmetrics
    from reportlab.pdfbase.ttfonts import TTFont
    pdfmetrics.registerFont(TTFont(*settings.ARTSHOW_BARCODE_FONT))

    c = Canvas(output,pagesize=letter)

    pdf = PdfReader ( settings.ARTSHOW_BLANK_BID_SHEET )
    xobj = pagexobj ( pdf.pages[0] )
    rlobj = makerl ( c, xobj )
    
    nfs_pdf = PdfReader ( settings.ARTSHOW_BLANK_NFS_SHEET )
    nfs_xobj = pagexobj ( nfs_pdf.pages[0] )
    nfs_rlobj = makerl ( c, nfs_xobj )

    sheet_offsets = [
        (0,5.5),
        (4.25,5.5),
        (0,0),
        (4.25,0),
        ]

    sheets_per_page = len(sheet_offsets)
    sheet_num = 0
    pieceiter = iter(pieces)
    if artshow_settings.ARTSHOW_BID_SHEET_PRECOLLATION:
        pieceiter = precollate_pieces(pieceiter)
    last_artist = None
    
    try:
        piece = pieceiter.next ()
        while True:
            try:
                for sheet_num in range(sheets_per_page):
                    if artshow_settings.ARTSHOW_BID_SHEET_PRECOLLATION:
                        if piece is None:
                            piece = pieceiter.next()
                            continue
                    else:
                        if piece.artist != last_artist and sheet_num != 0:
                            continue
                    c.saveState ()
                    c.translate ( sheet_offsets[sheet_num][0]*inch, sheet_offsets[sheet_num][1]*inch )
                    if piece.not_for_sale:
                        c.doForm ( nfs_rlobj )
                    else:
                        c.doForm ( rlobj )
                    c.saveState ()
                    c.setLineWidth ( 4 )
                    c.setFillColorRGB ( 1, 1, 1 )
                    c.setStrokeColorRGB ( 1, 1, 1 )
                    c.roundRect ( 1.1875*inch, 4.4375*inch, 1.75*inch, 0.5*inch, 0.0675*inch, stroke=True, fill=True )
                    c.restoreState ()
                    text_into_box ( c, u"*A"+unicode(piece.artist.artistid)+u"P"+unicode(piece.pieceid)+u"*", 1.3125, 4.6, 2.8125, 4.875, fontSize=13, style=barcode_style )
                    text_into_box ( c, "Artist "+unicode(piece.artist.artistid), 1.25, 4.4375, 2.0, 4.625 )
                    text_into_box ( c, "Piece "+unicode(piece.pieceid), 2.125, 4.4375, 2.875, 4.625 )
                    text_into_box ( c, piece.artist.artistname(), 1.125, 4.125, 3.875, 4.375 )
                    text_into_box ( c, piece.name, 0.75, 3.8125, 3.875, 4.0625 )
                    if piece.not_for_sale:
                        text_into_box ( c, piece.media, 0.875, 3.5, 2.375, 3.75 )
                    else:
                        text_into_box ( c, piece.media, 0.875, 3.5, 3.875, 3.75 )
                        text_into_box ( c, piece.not_for_sale and "NFS" or unicode(piece.min_bid), 3.25, 2.625, 3.75, 3.0 )
                        text_into_box ( c, piece.buy_now and unicode(piece.buy_now) or "N/A", 3.25, 1.9375, 3.75, 2.3125 )
                        text_into_box ( c, "X", 3.375, 0.375, 3.5625, 0.675, style=left_align_style, fontSize=16 )      
                    c.restoreState ()
                    last_artist = piece.artist
                    piece = pieceiter.next ()
            finally:
                c.showPage ()
    except StopIteration:
        pass

    c.save ()
开发者ID:chmarr,项目名称:artshow-fc2013,代码行数:77,代码来源:preprint.py

示例9: Report

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import doForm [as 别名]

#.........这里部分代码省略.........
        ## Create the page number label; 'Page X of'
        self.page_num = Field()
        self.page_num.style.horizontal_alignment = alignment.RIGHT
        self.page_num.style.vertical_alignment = alignment.TOP
        self.page_num.width = self._working_width - 13
        #self.page_num.style.color = (.6,.6,.6)
        self.page_num.horizontal_padding = 0
        self.page_num.style.size = 8

        ## Create the last page number label
        self.last_page = Field()
        #self.last_page.style.horizontal_alignment = alignment.LEFT
        self.last_page.style.vertical_alignment = alignment.TOP
        #self.last_page.width = self._working_width
        #self.last_page.style.color = (.6,.6,.6)
        self.last_page.horizontal_padding = 0
        self.last_page.style.size = 8

        ## Objects to be drawn
        self.draw_list = []

        self._page_count = 1

    #-----------------------------------------------------------------------Add

    def add(self, item):
        ## Add any object that, duck-typingly, has a 'draw_some' method
        self.draw_list.append(item)

    #--------------------------------------------------------------------Create

    def create(self):
        self.canvas.setAuthor(self.author)
        self.canvas.setTitle(self.title)
        self.canvas.setSubject('Python Generated Report')
        self._draw_header()
        self._draw_footer()
        vspace = self._working_height
        left = self.left_margin   
        right = self.page_width - self.right_margin

        for item in self.draw_list:
           
            while True:

                if vspace < 1:
                    self._start_new_page()
                    vspace = self._working_height  

                yoff = self.bottom_margin + vspace
                used = item.draw_some(self.canvas, left, right, yoff, vspace)
                
                if used == 0:
                    break

                else:
                    vspace -= used

        ## Add the numbering for last page
        ## We have to do this as a PDF 'Form' object since we don't know in
        ## advance how many pages there will be.
        self.canvas.beginForm('last_page')
        self.canvas.saveState()
        self.last_page.value = '%d' % self._page_count
        self.last_page.draw(self.canvas, 
            self._right_edge - ( self.right_margin + 14),
            self.bottom_margin * .65)
        self.canvas.restoreState()
        self.canvas.endForm()

        ## Close the PDF
        self.canvas.save()

    #----------------------------------------------------------------Start Page

    def _start_new_page(self):
        self._page_count += 1
        self.canvas.showPage()
        self._draw_header()
        self._draw_footer()

    #---------------------------------------------------------------Draw Header

    def _draw_header(self):
        self.header.value = self.title
        self.header.draw(self.canvas, self.left_margin, self._top_edge - 
            (self.top_margin * .65) )

    #---------------------------------------------------------------Draw Footer

    def _draw_footer(self):
        self.footer.value = self.author
        self.footer.draw(self.canvas, self.left_margin, 
            self.bottom_margin * .65)
        self.date.draw(self.canvas, self.left_margin,
            self.bottom_margin * .65)
        self.page_num.value = 'Page %d of ' % self._page_count
        self.page_num.draw(self.canvas, self.left_margin,
            self.bottom_margin * .65)
        self.canvas.doForm('last_page') 
开发者ID:Troush,项目名称:django-jobs-system,代码行数:104,代码来源:report.py

示例10: file_x

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import doForm [as 别名]
def file_x(route):
    input_file = route
    output_file = route.replace("static","static_pdf")
    print input_file

    # Get pages
    reader = PdfReader(input_file)
    pages = [pagexobj(p) for p in reader.pages]


    # Compose new pdf
    canvas = Canvas(output_file)

    for page_num, page in enumerate(pages, start=1):

        # Add page
        canvas.setPageSize((page.BBox[2], page.BBox[3]))
        canvas.doForm(makerl(canvas, page))

        # Draw footer
        footer_text = "Descargado desde https://UdpCursos.com"
        x = 180
        canvas.saveState()
        canvas.setFont('Times-Roman', 10)
        canvas.drawString(page.BBox[2]-x, 40, footer_text)
        canvas.restoreState()

        canvas.showPage()

    canvas.save()
开发者ID:malbammae,项目名称:UdpServices,代码行数:32,代码来源:pdf.py


注:本文中的reportlab.pdfgen.canvas.Canvas.doForm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。