Overview
TheDocumentComponent manages all document operations through specialized workers:
- ParserWorker: Converts input data to SII standard format
- NormalizerWorker: Calculates and validates required fields
- SanitizerWorker: Cleans and formats data
- ValidatorWorker: Ensures document compliance
- BuilderWorker: Constructs the final DTE with stamp and signature
- RendererWorker: Generates PDF or other output formats
Basic Document Creation
The simplest way to create a document is using thebill() method:
Document Creation Workflow
Thebill() method orchestrates the following steps:
Parse Input Data
The
ParserWorker converts your input data (array, JSON, XML) into the SII standard format.Build Document
The This includes:
BuilderWorker normalizes, sanitizes, validates, stamps, and signs the document.- Normalizing data (calculating totals, dates, etc.)
- Sanitizing values (trimming, formatting)
- Validating business rules
- Stamping with CAF (Timbre Electrónico)
- Signing with digital certificate
Working with DocumentBag
TheDocumentBag is a container that carries all document-related data through the creation process:
Supported Document Types
LibreDTE Core supports all Chilean electronic document types:Invoices
- Factura Afecta (33)
- Factura Exenta (34)
- Factura de Compra (46)
- Factura de Exportación (110)
Credit/Debit Notes
- Nota de Crédito (61)
- Nota de Débito (56)
- Nota de Crédito Exportación (112)
- Nota de Débito Exportación (111)
Receipts
- Boleta Afecta (39)
- Boleta Exenta (41)
Other Documents
- Guía de Despacho (52)
- Liquidación Factura (43)
Creating Multiple Items
The normalizer automatically calculates totals, IVA, and other required fields if not provided. You can let LibreDTE calculate them or provide explicit values.
Manual Document Building
For advanced use cases, you can use workers directly:Error Handling
Next Steps
Digital Signatures
Learn about signing documents with digital certificates
Document Validation
Validate documents against SII schemas and business rules
PDF Generation
Generate printable PDF versions of your documents
SII Integration
Send documents to SII and check their status