Overview
The API provides flexible PDF generation for all electronic documents with multiple format options, from standard A4 office documents to thermal receipt printers.Available Formats
The PDF service supports multiple paper formats optimized for different use cases:| Format | Dimensions | Best For | Description |
|---|---|---|---|
A4 | 210x297mm | Office/Email | Standard office format |
A5 | 148x210mm | Compact reports | Half of A4, compact |
80mm | 80x200mm | Thermal printer | Standard thermal receipt |
50mm | 50x150mm | Compact thermal | Small thermal printer |
ticket | 50x150mm | POS/Retail | Optimized ticket format |
Generating PDFs
Generate and Save
Generate a PDF and save it to the document:Download Directly
Download a PDF without saving:If a PDF was previously generated, the download endpoint returns the saved version. Use
generate-pdf to create a fresh copy.Format Query Parameter
PDF paper format:
A4: Standard office (210x297mm)A5: Compact (148x210mm)80mm: Thermal printer (80x200mm)50mm: Small thermal (50x150mm)ticket: Optimized ticket (50x150mm)
Get Available Formats
Query all supported formats with details:PDF Contents
All PDFs include:Header Section
- Company logo (if configured)
- Company information (RUC, business name, address)
- Branch information
- Document type and number
- Issue date and due date (invoices)
Client Section
- Client document type and number
- Legal/business name
- Address and contact information
Items Table
- Item code and description
- Quantity and unit of measure
- Unit value
- IGV/taxes
- Line total
Totals Section
- Subtotal (taxable operations)
- IGV amount
- Other taxes (ICBPER, ISC, IVAP)
- Total amount
- Amount in words
Footer Section
- QR code (SUNAT standard)
- Digital signature hash
- SUNAT response (if accepted)
- Payment terms (if credit)
QR Code Generation
All PDFs include a SUNAT-compliant QR code with the following format:Format-Specific Templates
A4 Format (Office)
- Full company branding
- Detailed item table with all columns
- Complete tax breakdown
- Professional layout for business use
- Email-friendly
- Email attachments to clients
- Printing for files/records
- B2B transactions
- Formal documentation
A5 Format (Compact)
- Reduced size for storage
- Simplified layout
- Essential information only
- Good for archiving
- Physical filing
- Reduced paper usage
- Internal records
80mm Thermal Format
- Optimized for 80mm thermal printers
- Vertical layout
- Condensed information
- No margins for thermal printing
- POS/Retail receipts
- Standard thermal printers
- Customer copies
- Quick printing
Ticket Format (50mm)
- Extra compact for small printers
- Minimal information
- Essential details only
- Very condensed layout
- Small thermal printers
- Mobile POS
- Compact receipts
- Space-constrained environments
Template Implementation
Fromapp/Services/PdfService.php, the PDF generation process:
Invoice PDF (Line 44-54)
- Prepares invoice data including company, client, details
- Generates QR code with SUNAT format
- Calculates totals and converts to words
- Renders template with format-specific layout
- Creates PDF using DomPDF library
- Returns PDF binary or saves to storage
Key Features
- Automatic calculations: All totals computed from details
- QR generation: SUNAT-compliant QR codes
- Number to words: Amount converted to Spanish text
- Format adaptation: Templates adjust to paper size
- Logo support: Company logos included when configured
Customization Options
Company Logo
Set company logo via the company configuration:Custom Colors
Templates use company brand colors if configured in the company settings.Additional Fields
Include extra information in PDFs viadatos_adicionales:
Implementation Example
Fromapp/Http/Controllers/Traits/HandlesPdfGeneration.php:15-65:
Best Practices
-
Choose the right format:
- A4 for business documents and emails
- 80mm for retail/POS systems
- Ticket for mobile/compact printers
-
Generate after SUNAT acceptance:
- QR codes include hash from accepted documents
- More accurate SUNAT response information
-
Store PDFs separately:
- Different formats for different uses
- Original A4 for records
- Thermal for customer copies
-
Include company logo:
- Professional appearance
- Brand consistency
- Better client recognition
-
Regenerate when needed:
- After document modifications
- When format requirements change
- For updated templates
Error Handling
Invalid Format
Document Not Found
PDF Generation Failed
Technical Details
DomPDF Configuration
Fromapp/Services/PdfService.php:521-535:
- Font: Arial (default)
- Remote resources: Enabled (for logos, external CSS)
- HTML5 parser: Enabled
- Paper orientation: Portrait
- Custom sizes: Converted from mm to points
Template System
Templates are located in Laravel Blade views:resources/views/pdf/invoice-{format}.blade.phpresources/views/pdf/boleta-{format}.blade.phpresources/views/pdf/credit-note-{format}.blade.phpresources/views/pdf/debit-note-{format}.blade.php
Number to Words
The system converts amounts to Spanish words (line 436-516):Batch PDF Generation
Generate PDFs for multiple documents:Performance Considerations
- PDF generation takes 1-3 seconds per document
- Large item lists increase generation time
- Images (logos) add processing time
- Consider background jobs for bulk generation
- Cache generated PDFs when possible
Common Use Cases
Retail POS System
Email Invoice to Client
Archive Documents
Next Steps
Multi-Company Setup
Configure multiple companies and branches
Creating Invoices
Learn about invoice creation and sending
