예제 #1
0
파일: topdown.py 프로젝트: watmough/jagpdf
def create_tiling_pattern(doc, mtx=None):
    pc = doc.canvas_create()
    pc.color_space("fs", jagpdf.CS_DEVICE_GRAY)
    pc.color("fs", 0)
    pc.state_save()
    pc.color("fs", 0.5)
    pc.translate(50, 50)
    pc.rotate(math.pi/4.)
    pc.scale(1, 0.5)
    pc.translate(-50, -50)
    pc.circle(50, 50, 50)
    pc.path_paint("fs")
    pc.state_restore()
    pc.move_to(5, 5)
    pc.line_to(95, 95)
    pc.path_paint("s")
    pc.text_start(5, 10)
    pc.text("text in pattern #1")
    pc.text_translate_line(0, 14)
    pc.text("text in pattern #2")
    pc.text_end()
    testlib.paint_image('/images/logo.png', doc, 5, 40, pc)
    spec = "step=100, 100"
    if mtx:
        mtx_s = ", ".join([str(i) for i in mtx])
        spec = spec + "; matrix=" + mtx_s
    return doc.tiling_pattern_load(spec, pc)
예제 #2
0
파일: topdown.py 프로젝트: watmough/jagpdf
def do_document(doc, canvas, topdown=False):
    # path
    canvas.move_to(50, 50)
    canvas.line_to(350, 50)
    canvas.line_to(200, 150)
    canvas.path_paint('sc')
    # text
    canvas.move_to(50, 170)
    canvas.line_to(450, 170)
    canvas.path_paint('s')
    fnt = doc.font_load("standard; name=Helvetica; size=40")
    canvas.text_font(fnt)
    if topdown:
        canvas.state_save()
        canvas.scale(1, -1)
    canvas.text(50, 170, 'Never say never!')
    if topdown:
        canvas.state_restore()
    # multiline text
    linespacing = fnt.height()
    basey = 550
    canvas.move_to(50, basey)
    canvas.line_to(450, basey)
    canvas.path_paint('s')
    canvas.color('s', 0.8)
    canvas.move_to(50, basey + linespacing)
    canvas.line_to(450, basey + linespacing)
    canvas.path_paint('s')
    canvas.color('s', 0.0)
    canvas.text_start(50, basey)
    canvas.text("Multiline #1")
    canvas.text_translate_line(0, linespacing)
    canvas.text("Multiline #2")
    canvas.text_end()
    # image
    canvas.move_to(50, 260)
    canvas.line_to(50, 230)    
    canvas.line_to(250, 230)
    canvas.line_to(250, 260)
    canvas.path_paint('s')
    testlib.paint_image('/images/logo.png', doc, 50, 230)
    canvas.state_save()
    canvas.translate(250, 230)
    canvas.scale(0.5, 0.5)
    testlib.paint_image('/images/logo.png', doc, 0, 0)
    canvas.state_restore()
    # shading pattern
    fn = doc.function_2_load("domain=0, 1; c0=0; c1=1")
    sh = doc.shading_pattern_load("axial; coords=170, 300, 270, 400",
                                  jagpdf.CS_DEVICE_GRAY,
                                  fn)
    canvas.state_save()
    canvas.color_space_pattern('f')
    canvas.pattern('f', sh)
    canvas.rectangle(150, 280, 140, 140)
    canvas.path_paint('fs')
    canvas.state_restore()
    canvas.move_to(170, 300)
    canvas.line_to(270, 400)
    canvas.path_paint('s')
    # scaled shading pattern
    mtx = testlib.Matrix()
    mtx.translate(400, 350)
    mtx.scale(.5, .5)
    mtx.translate(-400, -350)
    mtx_s = ", ".join([str(i) for i in mtx.data()])
    spec_str = "axial; coords=350, 300, 450, 400; matrix=%s" % mtx_s
    sh = doc.shading_pattern_load(spec_str,
                                  jagpdf.CS_DEVICE_GRAY,
                                  fn)
    canvas.state_save()
    canvas.color_space_pattern('f')
    canvas.pattern('f', sh)
    canvas.rectangle(330, 280, 140, 140)
    canvas.path_paint('fs')
    canvas.state_restore()
    canvas.move_to(375, 325)
    canvas.line_to(425, 375)
    canvas.path_paint('s')
    # shading operator
    canvas.state_save()
    sh = doc.shading_pattern_load("axial; coords=10, 10, 90, 90",
                                  jagpdf.CS_DEVICE_GRAY,
                                  fn)
    canvas.translate(25, 300)
    canvas.rectangle(0, 0, 100, 100)
    canvas.path_paint('w')
    canvas.shading_apply(sh)
    canvas.state_restore()
    # tiling pattern
    tp = create_tiling_pattern(doc)
    canvas.color_space_pattern('f')
    canvas.pattern('f', tp)
    canvas.rectangle(0, 400, 100, 100)
    canvas.path_paint("f")
    mtx = testlib.Matrix()
    mtx.translate(50, 50)
    mtx.scale(.5, .5)
    mtx.translate(-50, -50)
    tp_scaled = create_tiling_pattern(doc, mtx.data())
    canvas.pattern('f', tp_scaled)
    canvas.rectangle(125, 425, 100, 100)
    canvas.path_paint("fs")
    # pattern using another pattern
    tp2 = create_tiling_pattern2(doc)
    canvas.pattern('f', tp2)
    canvas.rectangle(300, 450, 100, 50)
    canvas.path_paint("f")
예제 #3
0
def test_main(argv=None):
    profile = jagpdf.create_profile()
    profile.set('doc.encryption', 'standard')
    profile.set("info.static_producer", "1")
    profile.set("doc.static_file_id", "1")
    profile.set("info.creation_date", "0")
    profile.set('stdsh.pwd_user', 'user')
    profile.set('stdsh.pwd_owner', 'owner')
    profile.set("stdsh.permissions", "no_print; no_copy")
    doc = testlib.create_test_doc(argv, 'topsecret.pdf', profile)
    fnt = doc.font_load("standard; name=Helvetica; size=10; enc=windows-1252")
    fnt_b = doc.font_load(
        "standard; name=Helvetica-Bold; size=10; enc=windows-1252")
    doc.page_start(597.6, 848.68)
    canvas = doc.page().canvas()
    canvas.color_space("fs", jagpdf.CS_DEVICE_RGB)
    # confidential
    canvas.state_save()
    cx, cy = 597.6 / 2, 848.68 / 2
    cfnt = doc.font_load(
        "standard; name=Helvetica-Bold; size=120; enc=windows-1252")
    canvas.text_font(cfnt)
    cf_w = cfnt.advance("TOP SECRET")
    cf_x = (597.6 - cf_w) / 2
    canvas.translate(cx, cy)
    canvas.rotate(3.14 / 3)
    canvas.translate(-cx, -cy)
    #canvas.text_rendering_mode('s')
    canvas.color('f', 0.8, 0.8, 0.8)
    canvas.text(cf_x, cy - 20, "TOP SECRET")
    canvas.state_restore()
    # page header
    fnt_clients = doc.font_load(
        "standard; name=Helvetica-Bold; size=13; enc=windows-1252")
    top_str = "Top 50 Clients"
    top_w = fnt_clients.advance(top_str)
    top_x = (597.6 - top_w) / 2
    canvas.text_font(fnt_clients)
    canvas.text(top_x, 785, top_str)
    # table
    widths = [150, 100, 100, 120]
    tbl = SimpleTable(doc, widths, font=fnt, header=1, footer=1, style=Style())
    # table header
    tbl.add_line(('Name', 'Account Nr.', 'Opened', 'Balance'))
    tbl.set_line_prop("font", 0, fnt_b)
    tbl.set_line_prop("halign", 0, "center")
    tbl.set_line_prop("cell_pad", 0, {'top': 4, 'bottom': 4})
    # table body
    for rec in records.split('\n')[:50]:
        tbl.add_line(rec.split('|'))
    tbl.set_column_prop("cell_pad", 0, {'left': 15})
    tbl.set_column_prop("cell_pad", 3, {'right': 15})
    tbl.set_column_prop("halign", 1, "center")
    tbl.set_column_prop("halign", 2, "center")
    tbl.set_column_prop("halign", 3, "right")
    # table footer
    tbl.add_line(4 * [])
    # table render
    tbl_width = sum(widths)
    tbl_x = (597.6 - tbl_width) / 2
    tbl.render(tbl_x, 780, canvas)
    # page footer
    fnt_clients = doc.font_load(
        "standard; name=Helvetica-Oblique; size=10; enc=windows-1252")
    canvas.text_font(fnt_clients)
    canvas.text(tbl_x, 40, "Classification: TOP SECRET")
    testlib.paint_image('/images/GWBush-signature.png', doc, tbl_x + 340, 10)
    # stamp
    testlib.paint_image('/images/topsecret.png', doc, 450, 20)
    #
    testlib.paint_image('/images/greedybank.png', doc, tbl_x, 790)
    #
    doc.page_end()
    doc.finalize()
예제 #4
0
def test_main(argv=None):
    profile = jagpdf.create_profile()
    profile.set("doc.encryption", "standard")
    profile.set("info.static_producer", "1")
    profile.set("doc.static_file_id", "1")
    profile.set("info.creation_date", "0")
    profile.set("stdsh.pwd_user", "user")
    profile.set("stdsh.pwd_owner", "owner")
    profile.set("stdsh.permissions", "no_print; no_copy")
    doc = testlib.create_test_doc(argv, "topsecret.pdf", profile)
    fnt = doc.font_load("standard; name=Helvetica; size=10; enc=windows-1252")
    fnt_b = doc.font_load("standard; name=Helvetica-Bold; size=10; enc=windows-1252")
    doc.page_start(597.6, 848.68)
    canvas = doc.page().canvas()
    canvas.color_space("fs", jagpdf.CS_DEVICE_RGB)
    # confidential
    canvas.state_save()
    cx, cy = 597.6 / 2, 848.68 / 2
    cfnt = doc.font_load("standard; name=Helvetica-Bold; size=120; enc=windows-1252")
    canvas.text_font(cfnt)
    cf_w = cfnt.advance("TOP SECRET")
    cf_x = (597.6 - cf_w) / 2
    canvas.translate(cx, cy)
    canvas.rotate(3.14 / 3)
    canvas.translate(-cx, -cy)
    # canvas.text_rendering_mode('s')
    canvas.color("f", 0.8, 0.8, 0.8)
    canvas.text(cf_x, cy - 20, "TOP SECRET")
    canvas.state_restore()
    # page header
    fnt_clients = doc.font_load("standard; name=Helvetica-Bold; size=13; enc=windows-1252")
    top_str = "Top 50 Clients"
    top_w = fnt_clients.advance(top_str)
    top_x = (597.6 - top_w) / 2
    canvas.text_font(fnt_clients)
    canvas.text(top_x, 785, top_str)
    # table
    widths = [150, 100, 100, 120]
    tbl = SimpleTable(doc, widths, font=fnt, header=1, footer=1, style=Style())
    # table header
    tbl.add_line(("Name", "Account Nr.", "Opened", "Balance"))
    tbl.set_line_prop("font", 0, fnt_b)
    tbl.set_line_prop("halign", 0, "center")
    tbl.set_line_prop("cell_pad", 0, {"top": 4, "bottom": 4})
    # table body
    for rec in records.split("\n")[:50]:
        tbl.add_line(rec.split("|"))
    tbl.set_column_prop("cell_pad", 0, {"left": 15})
    tbl.set_column_prop("cell_pad", 3, {"right": 15})
    tbl.set_column_prop("halign", 1, "center")
    tbl.set_column_prop("halign", 2, "center")
    tbl.set_column_prop("halign", 3, "right")
    # table footer
    tbl.add_line(4 * [])
    # table render
    tbl_width = sum(widths)
    tbl_x = (597.6 - tbl_width) / 2
    tbl.render(tbl_x, 780, canvas)
    # page footer
    fnt_clients = doc.font_load("standard; name=Helvetica-Oblique; size=10; enc=windows-1252")
    canvas.text_font(fnt_clients)
    canvas.text(tbl_x, 40, "Classification: TOP SECRET")
    testlib.paint_image("/images/GWBush-signature.png", doc, tbl_x + 340, 10)
    # stamp
    testlib.paint_image("/images/topsecret.png", doc, 450, 20)
    #
    testlib.paint_image("/images/greedybank.png", doc, tbl_x, 790)
    #
    doc.page_end()
    doc.finalize()