Ejemplo n.º 1
0
def test_main(argv=None):
    doc = testlib.create_test_doc(argv, 'invoice.pdf', jagpdf.create_profile())
    table_fnt = doc.font_load("standard; name=Helvetica; size=10; enc=windows-1250")
    table_fnt_bold = doc.font_load("standard; name=Helvetica-Bold; size=10; enc=windows-1250")
    header_fnt = doc.font_load("standard; name=Helvetica-Bold; size=10; enc=windows-1250")
    invoice_fnt = doc.font_load("standard; name=Helvetica-Bold; size=16; enc=windows-1250")
    offer_fnt = doc.font_load("standard; name=Helvetica-Bold; size=12; enc=windows-1250")
    table_title_fnt = doc.font_load("standard; name=Helvetica-Bold; size=14; enc=windows-1250")
    dingbats_fnt = doc.font_load("standard; name=ZapfDingbats; size=10")
    dingbats_fnt = header_fnt

    doc.page_start(597.6, 848.68)
    canvas = doc.page().canvas()
    canvas.color_space("fs", jagpdf.CS_DEVICE_RGB)
    #
    widths = [110, 90, 80, 80, 40, 80]
    style = TableStyle(doc)
    tbl = SimpleTable(doc, widths, font = table_fnt, style = style, header=1, footer=1)
    tbl.set_table_prop("halign", "center")

    # header
    tbl.add_line(('Number', 'Date', 'Time', 'Duration', 'Wiretap', 'Price'))
    tbl.set_line_prop("halign", 0, "center")
    tbl.set_line_prop("font", 0, header_fnt)
    tbl.set_line_prop("text_col", 0, (1, 1, 1))
    tbl.set_line_prop("cell_pad", 0, {'top': 4, 'bottom': 4})
    # body - add records and formatting style
    for rec, inf in record_iter():
        tbl.add_line(rec)
    tbl.set_column_prop("halign", 5, "right")
    tbl.set_column_prop("cell_pad", 5, {'right': 25})
    tbl.set_column_prop("halign", 4, "center")
    tbl.set_column_prop("text_col", 4, (0, .525, 0.086))
    tbl.set_column_prop("font", 4, dingbats_fnt)
    tbl.set_column_prop("halign", 3, "right")
    tbl.set_column_prop("cell_pad", 3, {'right': 25})
    tbl.set_column_prop("cell_pad", 0, {'left': 10})
    # footer
    dur = "%02d:%02d:%02d" % (inf.sec/3600, (inf.sec%3600)/60, inf.sec%60)
    price_str = "\x80 %.2f" % inf.price
    footer_id = tbl.add_line(('Total', '', '', dur, str(inf.nr_wire), price_str))
    tbl.set_line_prop("font", footer_id, header_fnt)
    tbl.set_line_prop("text_col", footer_id, (1, 1, 1))
    tbl.set_line_prop("cell_pad", footer_id, {'top': 4, 'bottom': 4})
    # render table
    tbl_width = sum(widths)
    tbl_x = (597.6 - tbl_width) / 2
    tbl.render(tbl_x, 670, canvas)
    #
    # render rest
    #
    # add customer, company, ...
    write_block(canvas, tbl_x, 765, billing_addres, table_fnt, table_fnt_bold)
    write_block(canvas, 400, 765, metelco_addres, table_fnt, table_fnt_bold)
    write_block(canvas, 205, 765, billing_info, table_fnt, table_fnt_bold)
    # invoice top
    png = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/images/metelco.png')
    logo = doc.image_load_file(png)
    canvas.image(logo, 390, 785)
    canvas.color("fs", *style.col_dark)
    canvas.text_font(table_title_fnt)
    canvas.text(260, 678, "Call Details")
    canvas.text_font(invoice_fnt)
    canvas.text(tbl_x, 790, "Invoice #3922094839")
    canvas.move_to(tbl_x, 780)
    canvas.line_to(tbl_x + tbl_width, 780)
    canvas.move_to(tbl_x, 695)
    canvas.line_to(tbl_x + tbl_width, 695)
    canvas.move_to(197, 775)
    canvas.line_to(197, 700)
    canvas.move_to(392, 775)
    canvas.line_to(392, 700)
    canvas.path_paint("s")
    # special offer
    jpg = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/images/oldphone.jpg')
    phone = doc.image_load_file(jpg)
    canvas.image(phone, tbl_x, 25)
    special_offer(doc, canvas, offer_fnt, tbl_x + 30, 110, 3.14/8)
    canvas.color('f', 0, 0, 0)
    rect = tbl_x + 130, 50, 340, 70
    textfmt.format_text(rect, ad, doc, table_fnt, align='justify', para_spacing=0.5)
    #
    doc.page_end()
    doc.finalize()
Ejemplo n.º 2
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()
Ejemplo n.º 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()