A Java-based PDF invoice generator built with Apache PDFBox that creates professional invoices with customizable sections.
- Features
- Prerequisites
- Installation
- Usage
- Project Structure
- API Reference
- Configuration
- Testing
- Contributing
- License
- PDF Invoice Generation: Creates professional PDF invoices using Apache PDFBox
- Modular Design: Sectioned approach with separate components for different invoice parts
- Custom Fonts: Supports custom Futura fonts for professional typography
- Flexible Data Input: Accepts customer information, invoice items, and billing details
- Invoice Sections:
- Header with company branding
- Customer information and billing address
- Itemized table with descriptions, quantities, and pricing
- Payment information and terms
- Tax calculations and totals
- Java 17 or higher
- Maven 3.6+ for dependency management and building
- Apache PDFBox 3.0.5 (managed via Maven)
-
Clone the repository:
git clone https://github.com/mikechiloane/invoice-generator.git cd invoice-generator
-
Build the project:
mvn clean compile
-
Run tests:
mvn test
-
Package the application:
mvn package
import com.recceda.invoice.api.InvoiceGenerator;
import com.recceda.invoice.common.CustomerInvoiceData;
import com.recceda.invoice.common.InvoiceItem;
// Create invoice items
InvoiceItem[] items = {
new InvoiceItem("Product A", 2, 75.0, "High quality product", "Electronics"),
new InvoiceItem("Service B", 1, 150.0, "Premium service", "Services")
};
// Create customer data
CustomerInvoiceData customerData = new CustomerInvoiceData(
"John Doe", // Customer name
new String[]{"123 Main St", "City, State 12345"}, // Address lines
items, // Invoice items
"2025-06-26", // Invoice date
"2025-07-26", // Due date
"300.00", // Subtotal
"24.00", // Tax amount
"8%", // Tax rate
"324.00" // Total amount
);
// Generate invoice
InvoiceGenerator generator = new InvoiceGenerator();
generator.generateInvoice(customerData, "output/invoice.pdf");
After building the project, you can run it using:
java -cp target/invoice-generator-1.0.0.jar com.recceda.invoice.api.InvoiceGenerator
invoice-generator/
βββ src/
β βββ main/
β β βββ java/com/recceda/invoice/
β β β βββ api/
β β β β βββ InvoiceGenerator.java # Main API class
β β β βββ common/
β β β β βββ CustomerInvoiceData.java # Data model for customer info
β β β β βββ InvoiceItem.java # Data model for invoice items
β β β β βββ TextUtils.java # Text utility functions
β β β βββ context/
β β β β βββ PdfContext.java # PDF rendering context
β β β βββ impl/sections/
β β β βββ HeaderSection.java # Invoice header rendering
β β β βββ PaymentInfoSection.java # Payment details section
β β β βββ PaymentTermsSection.java # Payment terms section
β β β βββ PdfSection.java # Base section interface
β β β βββ TableSection.java # Invoice items table
β β βββ resources/
β β βββ futura.ttf # Regular font
β β βββ futura_bold.ttf # Bold font
β β βββ logo.png # Company logo
β β βββ address # Company address file
β β βββ banking # Banking information
β β βββ contacts # Contact information
β β βββ payment_terms # Payment terms text
β βββ test/
β βββ java/com/recceda/invoice/
β βββ api/
β β βββ InvoiceGeneratorTest.java # API tests
β βββ impl/
β βββ ReccedaInvoiceTest.java # Implementation tests
βββ target/ # Maven build output
βββ pom.xml # Maven configuration
βββ README.md # This file
The main class for generating invoices.
public InvoiceGenerator()
Initializes a new invoice generator with default A4 page size and loads custom fonts.
public void generateInvoice(CustomerInvoiceData customerInvoiceData, String outputPath)
Generates a PDF invoice and saves it to the specified path.
Parameters:
customerInvoiceData
: Customer and invoice dataoutputPath
: File path where the PDF will be saved
Data model containing all information needed for invoice generation.
public CustomerInvoiceData(String customerName, String[] addressLines,
InvoiceItem[] items, String invoiceDate,
String invoiceDueByDate, String subTotal,
String tax, String taxRate, String total)
Represents a single item on the invoice.
public InvoiceItem(String itemName, Integer quantity, Double unitPrice,
String description, String category)
The application uses custom Futura fonts located in src/main/resources/
:
futura.ttf
- Regular fontfutura_bold.ttf
- Bold font
The following resource files can be customized:
address
- Company address informationbanking
- Banking and payment detailscontacts
- Contact informationpayment_terms
- Payment terms and conditionslogo.png
- Company logo image
- Page Size: A4 (210 Γ 297 mm)
- Font: Custom Futura fonts
- Layout: Professional invoice layout with header, itemized table, and footer sections
The project includes comprehensive unit tests:
# Run all tests
mvn test
# Run specific test class
mvn test -Dtest=InvoiceGeneratorTest
# Generate test reports
mvn surefire-report:report
- InvoiceGeneratorTest: Tests the main API functionality
- ReccedaInvoiceTest: Tests specific implementation details
Test reports are generated in target/surefire-reports/
.
mvn clean compile
mvn clean package
mvn test
mvn javadoc:javadoc
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow Java naming conventions
- Use meaningful variable and method names
- Add Javadoc comments for public methods
- Maintain consistent indentation (4 spaces)
This project is licensed under the MIT License - see the LICENSE file for details.
-
Font Loading Errors
- Ensure font files exist in
src/main/resources/
- Check file permissions
- Ensure font files exist in
-
PDF Generation Fails
- Verify output directory exists and is writable
- Check that all required data fields are provided
-
Build Failures
- Ensure Java 17+ is installed
- Run
mvn clean
before building
For issues and questions:
- Check existing GitHub issues
- Create a new issue with detailed description
- Include error logs and system information
Version: 1.0.0
Last Updated: June 26, 2025
Maintainer: Recceda Team