{"id":243,"date":"2025-11-20T14:45:01","date_gmt":"2025-11-20T14:45:01","guid":{"rendered":"https:\/\/codetypingpro.com\/?p=243"},"modified":"2025-11-20T14:45:01","modified_gmt":"2025-11-20T14:45:01","slug":"35-real-world-python-projects-pdf-invoice-generator","status":"publish","type":"post","link":"https:\/\/codetypingpro.com\/?p=243","title":{"rendered":"35 &#8211; Real-World Python Projects &#8211; PDF Invoice Generator"},"content":{"rendered":"\n<h6 class=\"wp-block-heading\"><\/h6>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Purpose<\/strong><\/h3>\n\n\n\n<p>Automatically generate professional PDF invoices for clients using Python.<br>Supports multiple items, tax calculation, totals, and auto-saving.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Used By (Real Life)<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Freelancers<\/li>\n\n\n\n<li>Small businesses<\/li>\n\n\n\n<li>Agencies<\/li>\n\n\n\n<li>E-commerce<\/li>\n\n\n\n<li>Billing &amp; Accounts teams<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\udde0 <strong>What This Project Will Do<\/strong><\/h1>\n\n\n\n<p>\u2714 Accept invoice details (client, items, cost, tax)<br>\u2714 Auto-calculate subtotals, tax, grand total<br>\u2714 Generate a <strong>professional PDF invoice<\/strong><br>\u2714 Auto-save with invoice number + date<br>\u2714 Optional email delivery<br>\u2714 Optional Excel log of all invoices<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\uddf0 <strong>Tech Stack<\/strong><\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>reportlab<\/code> (PDF generation)<\/li>\n\n\n\n<li><code>pandas<\/code> (optional for logging)<\/li>\n\n\n\n<li><code>datetime<\/code><\/li>\n\n\n\n<li><code>json<\/code><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udcc1 Folder Structure<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>PDF_Invoice_Generator\/\n\u2502\u2500\u2500 invoice_generator.py\n\u2502\u2500\u2500 invoice_template.json\n\u2502\u2500\u2500 output\/\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\uddfe <strong>invoice_template.json (Example)<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"invoice_number\": \"INV-2025-001\",\n  \"date\": \"2025-11-20\",\n  \"client_name\": \"ABC Technologies Pvt Ltd\",\n  \"client_address\": \"Bangalore, India\",\n  \"items\": &#91;\n    {\"description\": \"Website Development\", \"quantity\": 1, \"price\": 50000},\n    {\"description\": \"SEO Optimization\", \"quantity\": 1, \"price\": 15000},\n    {\"description\": \"Hosting (1 year)\", \"quantity\": 1, \"price\": 4000}\n  ],\n  \"tax_percent\": 18\n}\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udcc4 <strong>Full Python Code: <code>invoice_generator.py<\/code><\/strong><\/h1>\n\n\n\n<p>\u2714 Clean<br>\u2714 Professional<br>\u2714 Real-world ready<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import json\nfrom reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer\nfrom reportlab.lib import colors\nfrom reportlab.lib.pagesizes import A4\nfrom reportlab.lib.styles import getSampleStyleSheet\nfrom datetime import datetime\n\ndef generate_invoice(json_file):\n    with open(json_file) as f:\n        data = json.load(f)\n\n    invoice_no = data&#91;\"invoice_number\"]\n    date = data&#91;\"date\"]\n    client = data&#91;\"client_name\"]\n    address = data&#91;\"client_address\"]\n    items = data&#91;\"items\"]\n    tax_percent = data&#91;\"tax_percent\"]\n\n    # Output file name\n    filename = f\"output\/{invoice_no}.pdf\"\n    doc = SimpleDocTemplate(filename, pagesize=A4)\n    styles = getSampleStyleSheet()\n\n    content = &#91;]\n\n    # Title\n    content.append(Paragraph(\"&lt;b&gt;INVOICE&lt;\/b&gt;\", styles&#91;\"Title\"]))\n    content.append(Spacer(1, 20))\n\n    # Invoice Details\n    content.append(Paragraph(f\"Invoice No: {invoice_no}\", styles&#91;\"BodyText\"]))\n    content.append(Paragraph(f\"Date: {date}\", styles&#91;\"BodyText\"]))\n    content.append(Spacer(1, 10))\n\n    # Client Info\n    content.append(Paragraph(\"&lt;b&gt;Bill To:&lt;\/b&gt;\", styles&#91;\"Heading3\"]))\n    content.append(Paragraph(client, styles&#91;\"BodyText\"]))\n    content.append(Paragraph(address, styles&#91;\"BodyText\"]))\n    content.append(Spacer(1, 20))\n\n    # Table Header\n    table_data = &#91;&#91;\"Description\", \"Qty\", \"Price\", \"Total\"]]\n\n    subtotal = 0\n    for item in items:\n        total = item&#91;\"quantity\"] * item&#91;\"price\"]\n        subtotal += total\n        table_data.append(&#91;\n            item&#91;\"description\"],\n            item&#91;\"quantity\"],\n            f\"\u20b9{item&#91;'price']}\",\n            f\"\u20b9{total}\"\n        ])\n\n    tax_amount = round(subtotal * (tax_percent \/ 100), 2)\n    grand_total = subtotal + tax_amount\n\n    # Summary rows\n    table_data.append(&#91;\"\", \"\", \"Subtotal\", f\"\u20b9{subtotal}\"])\n    table_data.append(&#91;\"\", \"\", f\"Tax ({tax_percent}%)\", f\"\u20b9{tax_amount}\"])\n    table_data.append(&#91;\"\", \"\", \"Grand Total\", f\"\u20b9{grand_total}\"])\n\n    # Table\n    table = Table(table_data, colWidths=&#91;250, 50, 80, 80])\n    table.setStyle(TableStyle(&#91;\n        (\"BACKGROUND\", (0, 0), (-1, 0), colors.lightgrey),\n        (\"GRID\", (0, 0), (-1, -1), 1, colors.black),\n        (\"FONTNAME\", (0, 0), (-1, -1), \"Helvetica\"),\n        (\"ALIGN\", (1, 1), (-1, -1), \"CENTER\"),\n        (\"VALIGN\", (0, 0), (-1, -1), \"MIDDLE\")\n    ]))\n\n    content.append(table)\n    content.append(Spacer(1, 30))\n    content.append(Paragraph(\"&lt;b&gt;Thank you for your business!&lt;\/b&gt;\", styles&#91;\"BodyText\"]))\n\n    doc.build(content)\n\n    print(f\"Invoice generated: {filename}\")\n\n\nif __name__ == \"__main__\":\n    generate_invoice(\"invoice_template.json\")\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\uddfe <strong>Sample Output (PDF)<\/strong><\/h1>\n\n\n\n<p>\u2714 <strong>Invoice Number<\/strong><br>\u2714 <strong>Date<\/strong><br>\u2714 <strong>Client Info<\/strong><br>\u2714 <strong>Item Table<\/strong><br>\u2714 <strong>Subtotal + Tax + Grand Total<\/strong><br>\u2714 <strong>Professional Layout<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\ude80 <strong>Advanced Version (Optional Enhancements)<\/strong><\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 1. Email Invoice Automatically<\/h3>\n\n\n\n<p>Use Gmail SMTP \u2192 Send invoice PDF to the client.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 2. Automatic Invoice Number Generation<\/h3>\n\n\n\n<p>Format: <code>INV-2025-002<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 3. Company Logo<\/h3>\n\n\n\n<p>Insert an image at the top of PDF.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 4. Excel Log of All Invoices<\/h3>\n\n\n\n<p>Store every invoice in <code>invoices.xlsx<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 5. Multi-Currency Support<\/h3>\n\n\n\n<p>INR, USD, EUR, AED, SGD.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 6. Online API Version<\/h3>\n\n\n\n<p>Create a FastAPI endpoint:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>POST \/generate-invoice\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><\/h1>\n","protected":false},"excerpt":{"rendered":"<p>Purpose Automatically generate professional PDF invoices for clients using Python.Supports multiple items, tax calculation, totals, and auto-saving. Used By (Real Life) \ud83e\udde0 What This Project Will Do \u2714 Accept invoice details (client, items, cost, tax)\u2714 Auto-calculate subtotals, tax, grand total\u2714 Generate a professional PDF invoice\u2714 Auto-save with invoice number + date\u2714 Optional email delivery\u2714 Optional [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-243","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=243"}],"version-history":[{"count":1,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/243\/revisions"}],"predecessor-version":[{"id":244,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/243\/revisions\/244"}],"wp:attachment":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}