When an e-commerce business needs professional, branded invoices for every order, manual invoice creation becomes a time-consuming bottleneck. Spanisland, S.L. required an automated solution that would generate customized PDF invoices directly from their OpenCart e-commerce platform while maintaining their corporate branding and meeting Spanish invoicing regulations.

I integrated the Zend_Pdf library from Zend Framework into OpenCart, developing a custom invoice generation system that produced professional PDF invoices with a single click from the admin panel. The solution automated the entire invoicing workflow, from data extraction to PDF generation with corporate templates.


The Challenge: Automated Invoice Generation
E-commerce platforms like OpenCart provide robust order management but often lack comprehensive invoicing features, especially for markets like Spain with specific legal requirements.
Business Requirements:
- Professional PDF invoices - Branded documents matching corporate identity.
- Automated generation - Single-click invoice creation from admin panel.
- Complete order data - All relevant details automatically populated.
- Legal compliance - Meet Spanish invoicing regulations.
- Easy access - Generate invoices from order list or individual order views.
- Organized file management - Descriptive filenames for easy retrieval.
- Template flexibility - Easy updates to invoice design.
Technical Challenges:
- OpenCart integration - Extend platform without breaking core functionality.
- PDF generation - Programmatically create professional documents.
- Data extraction - Pull all necessary order information from OpenCart database.
- Template system - Use pre-designed PDF templates as base.
- Font embedding - Ensure consistent rendering across platforms.
- Spanish characters - Proper UTF-8 handling for accented characters.
Solution: Zend_Pdf Integration
The Zend Framework’s Zend_Pdf component provided the perfect foundation for PDF generation, offering:
- PDF template loading - Use existing PDF files as templates.
- Text overlay - Add dynamic content to template pages.
- Font management - Embed custom fonts for consistent rendering.
- UTF-8 support - Handle international characters properly.
- Styling capabilities - Control text formatting, colors, positioning.
- Production-ready - Battle-tested library used in enterprise applications.
Implementation
1. Zend Framework Integration
First step was integrating Zend_Pdf into OpenCart’s architecture:
Library Installation:
- Downloaded Zend Framework Zend_Pdf component.
- Placed library in OpenCart’s
system/external/directory. - Configured PHP include path for autoloading.
OpenCart Controller Extension:
/**
* Generates the PDF invoice
*
* @return void
*/
public function myinvoice() {
// Load Zend_Pdf class
set_include_path(get_include_path() . ":" . DIR_SYSTEM . "external/");
require_once(DIR_SYSTEM . 'external/Zend/Pdf.php');
$encoding = "UTF-8";
$templateName = "factura_spanisland";
$templatesDir = DIR_TEMPLATE . 'sale/';
$templateVersion = $this->_getLastPdfTemplateVersion($templateName, $templatesDir);
// Load PDF document from a file
$pdfTemplate = $templatesDir . $templateName . '_v' . $templateVersion . '.pdf';
$pdf = Zend_Pdf::load($pdfTemplate);
$page = $pdf->pages[0];
// Apply style
$style = $this->_getPdfTemplateStyle();
$page->setStyle($style);
// Define fonts
$font1 = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
$font2 = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
// Load invoice data and populate PDF...
}
2. Invoice Template System
Created branded invoice template in PDF format serving as the base for all generated invoices:
Template Design:
- Corporate header - Spanisland logo and company information.
- Invoice metadata - Invoice number, date, customer reference.
- Customer details - Billing and shipping addresses.
- Order items table - Products, quantities, prices, tax.
- Totals section - Subtotal, tax breakdown, total amount.
- Footer - Payment terms, legal information, contact details.
Template Versioning:
- Template files named with version numbers (
factura_spanisland_v1.pdf,factura_spanisland_v2.pdf). - System automatically selects latest version.
- Easy template updates without code changes.

3. Order Data Extraction
Extracted all necessary order information from OpenCart’s database:
Data Collection:
// Load order data
$this->load->model('sale/order');
$orders = array();
if (isset($this->request->post['selected'])) {
$orders = $this->request->post['selected'];
} elseif (isset($this->request->get['order_id'])) {
$orders[] = $this->request->get['order_id'];
}
foreach ($orders as $order_id) {
$order_info = $this->model_sale_order->getOrder($order_id);
if ($order_info) {
// Generate or retrieve invoice ID
if ($order_info['invoice_id']) {
$invoice_id = $order_info['invoice_prefix'] . sprintf("%04d", $order_info['invoice_id']);
} else {
$invoice_id = $this->model_sale_order->generateInvoiceId($order_id);
$order_info = $this->model_sale_order->getOrder($order_id);
$invoice_id = $order_info['invoice_prefix'] . sprintf("%04d", $order_info['invoice_id']);
}
// Extract order products
$products = $this->model_sale_order->getOrderProducts($order_id);
// Process and populate PDF...
}
}
Information Extracted:
- Invoice and order numbers with proper formatting.
- Customer details (name, billing address, shipping address).
- Order date and invoice date.
- Product list with descriptions, quantities, unit prices.
- Tax calculations and breakdowns.
- Shipping costs and payment method.
- Order totals.
4. PDF Population and Generation
Programmatically overlaid order data onto the PDF template:
Text Positioning:
- Calculated precise X/Y coordinates for each field.
- Used different fonts for headers, content, and totals.
- Applied bold formatting for emphasis where needed.
Dynamic Content:
- Invoice number and date in header.
- Customer information in designated sections.
- Product table with variable number of rows.
- Calculated tax amounts and totals.
- All Spanish characters (á, é, í, ó, ú, ñ, ¿, ¡) rendered correctly.

File Naming Convention:
Generated descriptive filenames for easy document management:
Format: Invoice_[InvoiceNumber]_Order_[OrderNumber]_[CustomerName]_[Date].pdf
Example: Invoice_2012-0042_Order_1234_Juan_Garcia_2012-01-22.pdf
This naming convention enabled:
- Quick identification of invoices.
- Chronological sorting.
- Easy customer reference lookup.
- Efficient document archiving.
5. Admin Panel Integration
Added invoice generation controls to OpenCart admin interface:
Order List Integration:
- “PDF Invoice” button added to each order row.
- Bulk invoice generation for multiple selected orders.
- Icon indicator for orders already invoiced.
Individual Order View:
- “Generate PDF Invoice” button in order detail screen.
- Immediate invoice generation and download.
- Invoice preview before saving.
User Workflow:
- Admin navigates to order list or individual order.
- Clicks “PDF Invoice” button.
- System generates invoice in seconds.
- PDF automatically downloads to admin’s computer.
- Admin can save and email invoice to customer.
Technical Features
PDF Generation Capabilities:
- Template-based - Use pre-designed PDFs as foundation.
- Dynamic text overlay - Add order data programmatically.
- Font embedding - Ensure consistent rendering.
- UTF-8 encoding - Support international characters.
- Multi-page support - Handle orders with many items.
- Table generation - Create formatted product tables.
OpenCart Integration:
- Non-invasive - Extends functionality without modifying core files.
- Admin panel access - Seamlessly integrated into existing interface.
- Order data access - Leverages OpenCart’s existing models.
- Invoice number tracking - Sequential invoice ID generation.
- Bulk operations - Generate multiple invoices at once.
Quality and Compliance:
- Professional appearance - Branded, polished invoices.
- Legal compliance - Met Spanish invoicing requirements.
- Data accuracy - Exact order information transfer.
- Consistent formatting - Uniform invoice appearance.
Project Outcome
The PDF invoice generation system successfully automated Spanisland’s invoicing process, delivering immediate business benefits.
Business Results:
- Time savings - Reduced invoice creation from 10 minutes to 10 seconds.
- Consistency - Every invoice followed corporate branding perfectly.
- Error reduction - Eliminated manual transcription errors.
- Professional image - Polished invoices enhanced company reputation.
- Scalability - Handled growing order volume effortlessly.
Technical Success:
- Seamless integration - No disruption to existing OpenCart workflows.
- Reliable operation - Consistent invoice generation without failures.
- Easy maintenance - Template updates without code changes.
- UTF-8 handling - Perfect rendering of Spanish characters.
Limitations and Trade-offs:
- Manual delivery - Invoices generated on-demand, not automatically emailed.
- Single template - One invoice design (easy to add more if needed).
- Admin-only - No customer self-service invoice download.
These limitations reflected the client’s specific requirements - they preferred manual review before sending invoices to customers, ensuring quality control on every transaction.
Lessons Learned
1. Library Selection Matters
Zend_Pdf proved an excellent choice for PDF generation. Its template-based approach meant designers could create invoice layouts in graphic tools, which were then programmatically populated - much easier than code-based PDF construction.
2. Template Versioning Provides Flexibility
Building version support into the template system from day one enabled painless invoice design updates. The business could refine their invoice layout without any code changes.
3. Descriptive Filenames Aid Organization
The comprehensive filename format (invoice number, order number, customer name, date) made document management significantly easier, especially when handling hundreds of invoices monthly.
4. UTF-8 Encoding Is Critical for International Markets
Proper UTF-8 handling throughout the system ensured Spanish characters rendered correctly. This required attention at every layer: PHP code, Zend_Pdf configuration, and font selection.
5. Non-Invasive Extensions Simplify Maintenance
By extending OpenCart without modifying core files, the system remained compatible with OpenCart updates and other plugins. This architectural decision prevented future maintenance headaches.
Conclusion
This PDF invoice generation project demonstrated how integrating specialized libraries like Zend_Pdf with e-commerce platforms can automate time-consuming business processes while maintaining professional quality. The solution transformed manual invoice creation into a single-click operation, freeing staff time for higher-value activities.
The template-based approach provided flexibility for future design changes, while the descriptive filename convention improved document organization. Most importantly, the system scaled effortlessly with business growth, handling increasing order volumes without additional effort.
For e-commerce businesses seeking invoice automation, combining proven libraries with thoughtful integration design delivers professional results without building complex systems from scratch.
Client: Spanisland, S.L.
Technologies: OpenCart, Zend Framework, Zend_Pdf, PHP
Project Duration: 1 month (2012)
About the author
Daniel López Azaña
Tech entrepreneur and cloud architect with over 20 years of experience transforming infrastructures and automating processes.
Specialist in AI/LLM integration, Rust and Python development, and AWS & GCP architecture. Restless mind, idea generator, and passionate about technological innovation and AI.
Related projects

SugarCRM Enterprise System for Electricity Distribution - Complete CRM with Custom Modules and Integrations
Comprehensive SugarCRM customization for Spanish electricity distribution company featuring 10+ custom modules for contracts, rates, consumption tracking, invoicing, tax reporting (Model 159), WordPress website integration for rate simulator and automated opportunity creation, Dropbox API integration for automated file processing, server deployment and hardening, backup policies, and scheduled email automation. 8-month ongoing development and maintenance delivering complete business management solution for energy sector.

Animal Shelter Solidarity Shop - PrestaShop E-commerce for Non-Profit Fundraising
Complete PrestaShop-based solidarity e-commerce platform developed pro-bono for Huellas Animal Shelter, featuring product catalog management, shopping cart, customer accounts, order processing, payment integration, and comprehensive admin panel. Ready-to-deploy solution available free for other animal shelters and NGOs. 2-month pro-bono development.

Apartment Rental Marketing Website - Digital Strategy to Stand Out in Economic Crisis
Personal marketing website created to successfully rent an apartment during Spain's 2010 economic crisis. Built on Joomla CMS, this single-property showcase site featured professional photography galleries, detailed property information, neighborhood highlights, and integrated contact forms. The project demonstrated how effective digital marketing and professional web presence can differentiate a property listing in a highly competitive, crisis-affected rental market. Successfully achieved rental to excellent tenants within target timeframe despite challenging economic conditions affecting Spain's construction and real estate sectors.
Comments
Submit comment