Skip to main content

access pygenpdf_json in a pythonic way (the pygenpdf-json library is a PDF generator)

Project description

pygenpdf

pygenpdf is the Pythonic way to create PDFs with pygenpdf_json(https://gitlab.com/numaelis/pygenpdf_json)


from pygenpdf import *

doc = Document()
doc.set_default_font( "/usr/share/fonts/truetype/liberation", "LiberationSans")
doc.set_title("report genpdf")
doc.set_paper_size(Size().A4())
doc.set_head_page(Paragraph("report genpdf-rs from python").aligned(Alignment.RIGHT).styled(Style().bold().italic().with_font_size(8)))
doc.set_margins(Margins().trbl(7,10,10,10))
# doc.add_font("/usr/share/fonts/truetype/noto", "NotoSans")
doc.set_line_spacing(1.0)


details = [["1", "Cafe", "1", "1000", "$1000"],
           ["3", "Chocolate", "2", "2000", "$4000"],
           ["5", "Medialuna salada", "2", "1500", "$3000"],
           ["2", "Factura crema", "2", "1500", "$3000"],
           ["8", "Chipa 100 gramos", "2", "3000", "$6000"]]

layout = VerticalLayout().framed(LineStyle().with_thickness(.1)).padded(1)
    
layout.push(
    Paragraph("Invoice").styled(Style().bold().with_font_size(25)).aligned(Alignment.CENTER)
    )

layout.push(
    Break(1)
    )

doc.push(layout)

doc.push(
    Break(2)
    )
    
doc.push(
    Paragraph("details").styled(Style().bold().with_font_size(12)).aligned(Alignment.CENTER)
    )
#table
table = TableLayout([1,2,1,1,1]).styled(Style())
#table.set_cell_decorator(FrameCellDecorator(True, True, True))
table.set_cell_decorator(FrameCellDecorator().with_line_style(True, True, True, LineStyle().with_thickness(.2).with_color(Color().rgb(210, 105, 30))))
table.push_row([
                    Paragraph("code").styled(Style().bold().italic()).aligned(Alignment.CENTER),
                    Paragraph("name").styled(Style().bold().italic()).aligned(Alignment.CENTER),
                    Paragraph("unit").styled(Style().bold().italic()).aligned(Alignment.CENTER),
                    Paragraph("count").styled(Style().bold().italic()).aligned(Alignment.CENTER),
                    Paragraph("total").styled(Style().bold().italic()).aligned(Alignment.CENTER),
                    ])
total = 0.0
for item in details:
    table.push_row([
                    Paragraph(item[0]).aligned(Alignment.CENTER),
                    Paragraph(item[1]).aligned(Alignment.LEFT).padded(Margins().vh(0,1)),
                    Paragraph(item[2]).aligned(Alignment.CENTER),
                    Paragraph(item[3]).aligned(Alignment.CENTER),
                    Paragraph(item[4]).aligned(Alignment.RIGHT),
                    ])  
    total += float(item[2]) * float(item[3])

doc.push(table)

doc.push(
    Break(2)
    )

layout_horizontal = HorizontalLayout([4,1])
layout_horizontal.push(
        Paragraph("Total").styled(Style().bold().with_font_size(14)).aligned(Alignment.RIGHT).padded(Margins().vh(0, 3))
    )
layout_horizontal.push(
        Paragraph("$"+str(total)).styled(Style().bold().with_font_size(14)).aligned(Alignment.RIGHT)\
        .framed(LineStyle().with_thickness(.3).with_color(Color().rgb(210, 105, 30)))
    )
doc.push(layout_horizontal)
doc.render_json_file("invoice.pdf") 



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygenpdf-0.1.2.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygenpdf-0.1.2-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file pygenpdf-0.1.2.tar.gz.

File metadata

  • Download URL: pygenpdf-0.1.2.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for pygenpdf-0.1.2.tar.gz
Algorithm Hash digest
SHA256 22cc483742297af3c3cdb6b6dc52388b94de5108b624c50a6613d7fbc913978f
MD5 84718a8da4b409539583eeae667c122b
BLAKE2b-256 1c63f6809b00ab508b523ed68d80d563cc3ae31f943fb7cf81e4413d29bb2d0e

See more details on using hashes here.

File details

Details for the file pygenpdf-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pygenpdf-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for pygenpdf-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab431481ef78b28dfde70440c2e61ff04aedb1876aed30c93e1239caddc637bd
MD5 30b239b724911636b0019e86cec65466
BLAKE2b-256 5234708fb9fd8d916c803acca56c0bc44d9e6b300650d9fe6b840dc44090da24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page