A modern, generic, customizable, and plug-and-play document generation framework with full internationalization (i18n) support and Moroccan legal compliance.
- ✅ Plugin Architecture - Easily extend with custom document types
- ✅ i18n Support - Multi-language support (English, French, Arabic)
- ✅ Generic Framework - Generate any type of document (invoices, bills, receipts, etc.)
- ✅ Moroccan Compliance - Full support for Moroccan laws and auto-entrepreneur regulations
- ✅ Configuration Management - Centralized, factory-based configuration
- ✅ Middleware & Hooks - Custom validators and transformers
- ✅ Multiple Output Formats - PDF, HTML (easily extensible)
- ✅ Backward Compatible - Legacy API still works
npm install @omnizya/legmanimport DocumentFactory from '@omnizya/legman'
import { PDFDocumentGenerator } from '@omnizya/legman'
// Create factory
const factory = new DocumentFactory()
await factory.initialize('en') // English
// Setup company
factory.setCompanyInfo({
name: 'My Company',
address: '123 Business St',
city: 'New York',
phone: '+1 (555) 123-4567',
email: 'info@mycompany.com'
})
// Create generator
const generator = factory.createGenerator('pdf')
// Generate PDF
const pdfBuffer = await generator.generateBuffer({
OrderNumber: 'INV-001',
IssueDate: new Date(),
Items: [
{ Description: 'Service', PriceExcludingVat: 1000 }
],
Currency: 'MAD',
PriceExcludingVat: 1000,
VatAmount: 200,
TotalPrice: 1200
})import DocumentFactory from '@omnizya/legman'
// Enable Moroccan compliance
const factory = new DocumentFactory()
await factory.initialize('ar') // Arabic
factory.enableMoroccoCompliance()
factory.enableAutoEntrepreneur({
activityType: 'services' // 'services' (1%), 'commerce' (0.5%), 'artisana' (0.5%)
})
// For high-value invoices (>80,000 MAD for single client), 30% withholding tax applies automatically
// Setup Moroccan company info
factory.setCompanyInfo({
name: 'شركتي',
address: '123 شارع الأعمال',
city: 'الرباط',
ice: '123456789',
rc: 'RC12345',
patente: 'PAT123',
cnss: 'CNSS123'
})
// Create auto-entrepreneur invoice generator
const generator = factory.createGenerator('pdf', {
documentType: 'autoEntrepreneurInvoice'
})
// Generate compliant invoice
const pdfBuffer = await generator.generateBuffer({
OrderNumber: 'AE-INV-001',
IssueDate: new Date(),
Items: [
{ Description: 'خدمة', PriceExcludingVat: 1000 }
],
PriceExcludingVat: 1000
})The main entry point for document generation. Manages everything centrally.
const factory = new DocumentFactory()
// Initialize with language
await factory.initialize('en')
// Configure globally
factory.setConfig({
language: 'en',
dateFormat: 'L',
defaultCurrency: 'MAD'
})
// Set company info
factory.setCompanyInfo({
name: 'Your Company',
address: '...',
// ... other fields
})
// Change language at runtime
factory.setLanguage('fr')Register and use plugins for different document types.
// Register a custom plugin
factory.registerPlugin('custom', {
name: 'Custom Document',
type: 'generator',
description: 'My custom document type'
})
// Use it
const generator = factory.createGenerator('custom')Full support for Moroccan business regulations:
- Auto-Entrepreneur Invoices: Simplified invoices for self-employed individuals
- Tax Calculations: Automatic tax calculation based on activity type:
- Services: 1% tax rate
- Commerce/Artisana: 0.5% tax rate
- High-value invoices (>80,000 MAD for single client): 30% withholding tax (RAS)
- Legal Requirements: Compliance with Moroccan invoice format requirements
- Arabic Support: Full Arabic language support for Moroccan documents
invoice- Standard invoicesbill- Billsreceipt- ReceiptsautoEntrepreneurInvoice- Moroccan auto-entrepreneur invoices
- English (
en) - French (
fr) - Arabic (
ar)
initialize(language)- Initialize with languagesetCompanyInfo(info)- Set company informationsetConfig(config)- Set global configurationsetLanguage(language)- Change languagecreateGenerator(type, options)- Create document generatorenableMoroccoCompliance()- Enable Moroccan compliance modeenableAutoEntrepreneur(options)- Enable auto-entrepreneur mode
generateBuffer(content, options)- Generate as buffergenerateDownload(content, filename, options)- Download filegenerateViewer(content, options)- Open in viewergeneratePrint(content, filename, options)- Print document
Contributions are welcome! Please see our Contributing Guide for details.
MIT License - see LICENSE for details.
For support, please contact us at support@omnizya.com or create an issue on GitHub.