@nestjsforge/pdfme
Overview
NestJS module for PDF generation using the pdfme library as injectable services.
A NestJS module that wraps pdfme as a first-class injectable service. Configure once with forRoot or forRootAsync, then inject PdfmeService anywhere in your application to generate PDF documents from templates with zero boilerplate.
Key Features
- Native NestJS DI — Inject
PdfmeServicedirectly into controllers, services, and providers. - forRoot / forRootAsync — Sync and async configuration (useFactory, useClass, useExisting).
- Typed exceptions — Structured error classes for generation, template, and font failures.
- Custom fonts — Register custom font files with the NestJS DI container.
- Custom plugins — Extend pdfme with custom rendering plugins.
- Dual CJS/ESM — Works in both CommonJS and ES Module NestJS applications.
- Fully tested — Unit and integration test coverage.
- Zero boilerplate — Skip the repetitive pdfme setup — just configure and inject.
Quick Example
import { PdfmeModule } from '@nestjsforge/pdfme';
@Module({
imports: [
PdfmeModule.forRoot({
fonts: { NotoSans: { data: readFileSync('./fonts/NotoSans.ttf'), fallback: true } },
}),
],
})
export class AppModule {}import { PdfmeService } from '@nestjsforge/pdfme';
@Injectable()
export class InvoiceService {
constructor(private readonly pdfme: PdfmeService) {}
async generateInvoice(data: InvoiceData): Promise<Uint8Array> {
return this.pdfme.generate({
template: invoiceTemplate,
inputs: [{ invoiceNumber: data.number, total: data.total }],
});
}
}