You can generate a PDF report in Peliqan in different ways. In this example, we are using HTML to have full control over the layout over the report.

The Streamlit module in Peliqan (st) is only used in this example to render the HTML. Next we use the Peliqan module (pq) to convert the Streamlit output on screen to a PDF document.

Example low-code Python script in Peliqan:

import html, pdfkit

dbconn = pq.dbconnect('dw_123')
data = dbconn.fetch('db_name', 'schema_name', 'INVOICES')
data = data[["DISPLAY_NAME", "ACCOUNT_ID", "COMPANY_ID", "QUANTITY", "PRODUCT_ID", "PRICE_TOTAL"]]

report  = "<body style='margin: 20; padding: 20'>\\n"
report += "<style>td { padding: 15px; background-color: #D6EAF8; }</style>"

report += "<h1>Invoicing report</h1>\\n"
report += "<img src='https://.../logo.svg' width=100><br><br>\\n"
report += "<h3>Invoice lines</h3>\\n"
report += "<table>\\n"
for i, row in data.iterrows():
    report += "<tr>\\n  "
    for col in row:
      report += "<td>%s</td>" % html.escape(str(col))
    report += "\\n</tr>\\n"
report += "</table>\\n"
report += "</body>\\n"

data = dbconn.fetch('db_name', 'schema_name', 'Invoice_summary') # Query in Peliqan (Group by)

report += "<br><br><h3>Summary by product</h3>\\n"
report += "<table>\\n"
for i, row in data.iterrows():
    report += "<tr>\\n  "
    for col in row:
      report += "<td>%s</td>" % html.escape(str(col))
    report += "\\n</tr>\\n"
report += "</table><br><br>\\n"

st.markdown(report, unsafe_allow_html=True)

pq.download_pdf_button(report, file_name = "report.pdf", label = "Download PDF")