This Python script utilizes the fpdf
library to generate PDF invoices from Excel files located in the "invoices" directory. Each Excel file represents an invoice and is converted into a PDF document with detailed information about the products, total prices, and a summary.
- Python 3.x
- Install the
fpdf
andpandas
libraries using:pip install fpdf pandas
- Place your Excel invoice files (with a
.xlsx
extension) in the "invoices" directory. - Run the script using:
python main.py
- The script will convert each Excel invoice into a corresponding PDF and save it in the "pdfs" directory.
-
Import Libraries
- The script imports necessary libraries:
fpdf
,pandas
,glob
, andpathlib
.
- The script imports necessary libraries:
-
Retrieve Filepaths
- The script retrieves the filepaths of all Excel files in the "invoices" directory using
glob
.
- The script retrieves the filepaths of all Excel files in the "invoices" directory using
-
Generate PDF for Each Invoice
- For each Excel file, a new PDF is generated.
- Extract invoice number and date from the filename.
- Read the Excel file into a pandas DataFrame.
- Iterate over DataFrame rows and populate the PDF with product details.
- Calculate and display the total sum of the invoice.
- Save the PDF in the "pdfs" directory with the same filename.
-
Customization
- You can customize the script by adjusting the column names used in the PDF generation (e.g., 'product_id', 'product_name', 'amount_purchased', 'price_per_unit', 'total_price').
-
Additional Customization Options
- You can add a company name and logo to the invoice by modifying the corresponding sections in the script.
- Ensure that the "invoices" directory contains valid Excel files with the expected structure.
- Check the "pdfs" directory for the generated PDF invoices.
- Customize the script to fit your specific invoice format, company details, and branding.
Feel free to modify the script to suit your specific invoicing requirements.