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


Python Canvas.getpdfdata方法代码示例

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


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

示例1: process_pdf

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import getpdfdata [as 别名]
 def process_pdf(self, image_data, hocr_data, pdf_filename):
     """Utility function if you'd rather get the PDF data back instead of save it automatically."""
     pdf = Canvas(pdf_filename, pageCompression=1)
     pdf.setCreator('hocr-tools')
     pdf.setPageSize((self.width, self.height))
     pdf.drawImage(image_data, 0, 0, width=self.width, height=self.height)
     pdf = self.add_text_layer(pdf, hocr_data)
     pdf_data = pdf.getpdfdata()
     return pdf_data
开发者ID:uml-digitalinitiatives,项目名称:pdf_to_book_batch_converter,代码行数:11,代码来源:hocrpdf.py

示例2: Watermark

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import getpdfdata [as 别名]
class Watermark(object):

    def __init__(self):
        self.canvas = Canvas('watermark.pdf', pagesize=(612, 792))

    def sign(self, x, y, phrases=(), dx=0):
        c = self.canvas
        c.drawImage('../signature.png', x=x, y=y, width=120, height=100,
                    mask='auto', preserveAspectRatio=True, anchor='sw')
        for phrase in phrases:
            y -= 14
            c.drawString(x + 20 + dx, y, phrase)

    def page(self):
        self.canvas.showPage()
        return PdfFileReader(StringIO(self.canvas.getpdfdata())).getPage(0)
开发者ID:brandon-rhodes,项目名称:python-johnhancock,代码行数:18,代码来源:__main__.py

示例3: main

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import getpdfdata [as 别名]
def main():
    pdfmetrics.registerFont(TTFont('Dosis', 'Dosis-Medium.ttf'))

    stars = []
    with open('bsc5.dat', 'rb') as f:
        for line in f:
            line = '.' + line  # switch to 1-based indexing
            if not line[62].strip():
                continue  # skip coordinate-less novas
            letter = intern(line[8:11])
            if letter == '   ':
                letter = None
            h, m, s = float(line[61:63]), float(line[63:65]), float(line[65:69])
            ra = (h + (m + s / 60.0) / 60.0) * tau / 24.0
            d, m, s = float(line[69:72]), float(line[72:74]), float(line[76:78])
            dec = (d + (m + s / 60.0) / 60.0) * tau / 360.0
            mag = float(line[103:108])
            stars.append((letter, ra, dec, mag))

    h, w = 48, 96
    c = Canvas('logo.pdf', pagesize=(w, h))

    c.setFillColor('white')
    c.rect(0, 0, w, h, stroke=0, fill=1)

    c.setFillColor(bright_star_color)

    rotation = 10.0 * tau / 360.0
    # magscale = 0.1
    # For 10 degrees:
    x_offset = 96 -33.5
    y_offset = h  +37.5
    # For 15 degrees:
    # x_offset = 96 -28.5
    # y_offset = 96 +0.5
    # for 45 degrees:
    # x_offset = 96 -13.5
    # y_offset = 96 -10

    small_glyphs = []
    c.setFont('Helvetica', 2)

    for letter, ra, dec, mag in stars:
        # if mag > 4.0:
        #     continue
        d = - (dec - quarter_tau) * 100
        ra += rotation
        x = d * sin(ra)
        y = d * cos(ra)

        if y < -63.0 or y > -39.0:
            continue
        if x < -43.0 or x > 19.0:
            continue

        x += x_offset
        y += y_offset

        r = ((13.0 - mag) / 10.0) ** 4.0 #* magscale
        r = min(r, 1.0)

        if r < 0.5:
            small_glyphs.append((x, y, r))
        else:
            if letter is not None:
                c.saveState()
                greek_letter, offset = greeks[letter]
                c.setFillColor(greek_color)
                c.drawString(x+offset, y+0.5, greek_letter)
                if letter == 'Alp':
                    c.setFillColor(alpha_star_color)
                    c.circle(x, y, r, stroke=0, fill=1)
                c.restoreState()
                if letter != 'Alp':
                    c.circle(x, y, r, stroke=0, fill=1)
            else:
                c.circle(x, y, r, stroke=0, fill=1)


    c.setFillColor(dim_star_color)
    for x, y, r in small_glyphs:
        c.circle(x, y, r, stroke=0, fill=1)

    c.setFillColor(text_color) #, alpha=0.5)
    c.setFont('Dosis', 24)
    sw = c.stringWidth('Skyfield')
    c.drawString(w // 2 - sw // 2, h - 40, 'Skyfield')

    c.showPage()
    with open('logo.pdf', 'wb') as f:
        f.write(c.getpdfdata())
开发者ID:SeanBE,项目名称:python-skyfield,代码行数:93,代码来源:logo.py

示例4: print_many_areas

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import getpdfdata [as 别名]
def print_many_areas(areas):
    init_pdf()

    c = Canvas('1.pdf', pagesize = A4)

    x = (A4[0] - BLANK_WIDTH) / 2
    y = (A4[1] - 3*BLANK_HEIGHT) / 2


    map_urls = [ build_map_url(area.x, area.y, area.zoom, area.marks) for area in areas ]


    urls_to_fetch = []
    map_pngs = {}
    for url in map_urls:
        png = MapCache.get_map(url)
        if png:
            map_pngs[url] = png
        else:
            urls_to_fetch.append(url)


    if urls_to_fetch:
        pool = multiprocessing.Pool(16)
        fetched_pngs = pool.map(fetch_map, urls_to_fetch)
        pool.close()
    else:
        fetched_pngs = []


    for url, png in izip(urls_to_fetch, fetched_pngs):
        if png is None:
            raise Exception("Cannot fetch {0}".format(url))
        map_pngs[url] = png

    map_images = {}
    for url, png in map_pngs.iteritems():
        map_images[url] = adjust_colors(Image.open(StringIO.StringIO(png)).convert('RGB'))


    # Saving PNG to MapCache only after creating Image from it to insure it is proper PNG
    for url, png in izip(urls_to_fetch, fetched_pngs):
        MapCache.save_map(url, png)


    for page_no in xrange((len(areas) + 2) / 3):
        page_set = areas[page_no*3 : (page_no+1)*3]

        c.setLineWidth(0.5)
        c.setStrokeGray(0.5)
        c.line(x, 0, x, A4[1])
        c.line(x + BLANK_WIDTH, 0, x + BLANK_WIDTH, A4[1])

        c.line(0, y + 3*BLANK_HEIGHT, A4[0], y + 3*BLANK_HEIGHT)

        print_area_blank(c, x, y + 2*BLANK_HEIGHT, areas[page_no*3 + 0], map_images[map_urls[page_no*3 + 0]])
        c.line(0, y + 2*BLANK_HEIGHT, A4[0], y + 2*BLANK_HEIGHT)

        if len(page_set) >= 2:
            print_area_blank(c, x, y + BLANK_HEIGHT, areas[page_no*3 + 1], map_images[map_urls[page_no*3 + 1]])
            c.line(0, y + BLANK_HEIGHT, A4[0], y + BLANK_HEIGHT)

        if len(page_set) >= 3:
            print_area_blank(c, x, y, areas[page_no*3 + 2], map_images[map_urls[page_no*3 + 2]])
            c.line(0, y, A4[0], y)

        c.showPage()


    return c.getpdfdata()
开发者ID:IlyaSkriblovsky,项目名称:jwter,代码行数:72,代码来源:printer.py


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