8.2 KiB
@design.estate/dees-document
A powerful TypeScript framework for dynamically generating professional business documents like invoices with web components and PDF export capabilities. 🧾
Issue Reporting and Security
For reporting bugs, issues, or security vulnerabilities, please visit community.foss.global/. This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a code.foss.global/ account to submit Pull Requests directly.
Installation
pnpm install @design.estate/dees-document
Features
- 📄 PDF Generation - Server-side PDF creation from structured data using Puppeteer
- 🎨 Web Components - Lit-based custom elements for document rendering
- 🌍 Multi-language Support - Built-in translation system (EN, DE, ES)
- 📱 Automatic Pagination - Smart content overflow handling across pages
- 💳 QR Payment Codes - EPC QR codes for SEPA payments
- 🖨️ Print Mode - Optimized rendering for both screen and print
- 📐 A4 Format - Precise DIN A4 document dimensions
- ✨ Theming - Customizable colors, backgrounds, and branding
Usage
Server-Side PDF Generation
import { PdfService } from '@design.estate/dees-document';
import type { TInvoice } from '@tsclass/tsclass/finance';
// Initialize the PDF service
const pdfService = new PdfService({});
await pdfService.start();
// Create invoice data
const invoice: TInvoice = {
type: 'invoice',
invoiceType: 'debitnote',
id: 'INV-2024-001',
invoiceId: 'INV-2024-001',
date: Date.now(),
currency: 'EUR',
dueInDays: 30,
reverseCharge: false,
from: {
name: 'Your Company GmbH',
type: 'company',
status: 'active',
address: {
streetName: 'Business Street',
houseNumber: '123',
city: 'Berlin',
country: 'Germany',
postalCode: '10115',
},
sepaConnection: {
bic: 'DEUTDEFF',
iban: 'DE89370400440532013000',
},
registrationDetails: {
vatId: 'DE123456789',
registrationName: 'Amtsgericht Berlin',
registrationId: 'HRB 12345',
},
},
to: {
name: 'Customer Inc.',
type: 'company',
status: 'active',
address: {
streetName: 'Client Avenue',
houseNumber: '456',
city: 'Munich',
country: 'Germany',
postalCode: '80331',
},
registrationDetails: {
vatId: 'DE987654321',
},
},
items: [
{
name: 'Web Development Services',
unitQuantity: 40,
unitNetPrice: 95,
unitType: 'hours',
vatPercentage: 19,
position: 1,
},
{
name: 'Hosting (Annual)',
unitQuantity: 1,
unitNetPrice: 299,
unitType: 'item',
vatPercentage: 19,
position: 2,
},
],
subject: 'Invoice INV-2024-001',
versionInfo: {
type: 'final',
version: '1.0.0',
},
};
// Generate PDF
const pdfResult = await pdfService.createPdfFromLetterObject({
letterData: invoice,
documentSettings: {
languageCode: 'EN',
enableDefaultHeader: true,
enableDefaultFooter: true,
enableFoldMarks: true,
dateStyle: 'long',
},
});
// Save to file
import { SmartFs, SmartFsProviderNode } from '@push.rocks/smartfs';
const fs = new SmartFs(new SmartFsProviderNode());
await fs.file('./invoice.pdf').write(Buffer.from(pdfResult.buffer));
// Don't forget to stop the service when done
await pdfService.stop();
Document Settings
Customize document appearance with IDocumentSettings:
const documentSettings = {
// Language for translations
languageCode: 'DE', // 'EN' | 'DE' | 'ES'
// Layout options
enableDefaultHeader: true,
enableDefaultFooter: true,
enableFoldMarks: true,
enableTopDraftText: true,
enableInvoiceContractRefSection: true,
// Display options
vatGroupPositions: true,
dateStyle: 'long', // 'short' | 'medium' | 'long' | 'full'
// Theming
theme: {
colorPrimaryForeground: '#ffffff',
colorPrimaryBackground: '#e4002b',
colorAccentForeground: '#333333',
colorAccentBackground: '#f5f5f5',
pageBackground: 'url(your-watermark.png)',
coverPageBackground: 'url(your-cover.png)',
},
};
Web Component Usage
For browser-based document viewing:
import '@design.estate/dees-document/web';
// In your HTML/Lit template
html`
<dedocument-viewer
.letterData=${invoiceData}
.documentSettings=${documentSettings}
></dedocument-viewer>
`;
// Or render the document directly
html`
<dedocument-dedocument
.letterData=${invoiceData}
.documentSettings=${documentSettings}
></dedocument-dedocument>
`;
Translation System
The package includes a translation system for multi-language document generation:
import { translate } from '@design.estate/dees-document/shared';
// Translate document labels
translate('DE', 'invoice@@totalGross'); // "Gesamtbetrag (Brutto)"
translate('EN', 'invoice@@totalGross'); // "Total (Gross)"
translate('ES', 'invoice@@totalGross'); // "Total (Bruto)"
Module Exports
The package provides multiple entry points:
// Node.js server-side (PDF generation)
import { PdfService } from '@design.estate/dees-document';
import { PdfService } from '@design.estate/dees-document/node';
// Browser web components
import '@design.estate/dees-document/web';
// Shared utilities and types
import { translate, IDocumentSettings } from '@design.estate/dees-document/shared';
// TypeScript interfaces
import type { IDocumentSettings } from '@design.estate/dees-document/interfaces';
Document Components
The framework includes these web components:
| Component | Description |
|---|---|
<dedocument-dedocument> |
Main document container with pagination |
<dedocument-viewer> |
Document viewer with controls |
<dedocument-page> |
Single A4 page with scaling support |
<dedocument-pageheader> |
Company logo and branding header |
<dedocument-letterheader> |
Sender/recipient addresses |
<dedocument-pagecontent> |
Main content area |
<dedocument-pagefooter> |
Company info and page numbers |
<dedocument-contentinvoice> |
Invoice-specific content layout |
<dedocument-paymentcode> |
EPC QR code for SEPA payments |
Draft vs Final Documents
Control document version display:
const invoice = {
// ... other fields
versionInfo: {
type: 'draft', // Shows watermark "DRAFT" across pages
version: '0.1.0',
},
};
// For final documents
const invoice = {
// ... other fields
versionInfo: {
type: 'final', // Clean document without watermark
version: '1.0.0',
},
};
License and Legal Information
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the LICENSE file.
Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
Company Information
Task Venture Capital GmbH Registered at District Court Bremen HRB 35230 HB, Germany
For any legal inquiries or further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.