@the-serial-coder/pdf-schema
v1.0.2
Published
  
Readme
Pdf Schema
A TypeScript library built on top of pdfmake to generate PDFs with flexible configurations, including printing, downloading, or exporting as a PDF.
Features
- Works seamlessly with TypeScript
- Supports multiple page sizes including
A4,LETTER, and custom dimensions - Configurable fonts, colors, and styles
- Can output PDFs, trigger print, or download directly
- Lightweight and easy to integrate
Installation
npm install @the-serial-coder/pdf-schemaMain Config
The library is configured using the PdfConfig type:
type PdfActionType = 'print' | 'pdf' | 'download';
interface PdfConfig {
pageSize: PdfPageSize;
noOfPrint?: number;
fontConfig?: {
fontSize: number;
color: string;
bold: boolean;
font: 'Preeti' | 'Roboto' | 'Inter';
italics: boolean;
};
canvas?: boolean;
canvasX?: [number, number];
canvasY?: [number, number];
margin?: MarginArray;
}
type PdfPageSize =
| 'A0' | 'A1' | 'A2' | 'A3' | 'A4' | 'A5' | 'A6'
| 'LETTER' | 'LEGAL' | 'TABLOID' | 'EXECUTIVE'
| { width: number; height: number };
interface PdfData {
miscellaneous?: { printCounter: number };
background?: {
footers?: BackgroundFooters;
headers?: BackgroundHeaders;
};
headers?: Headers;
content?: ContentBlock[];
footers?: Footers;
}Main Function
The primary function to generate or handle PDFs:
function handlePdfAction(
action: PdfActionType,
pdfData: PdfData,
pdfConfig: PdfConfig,
callback?: () => void
)action: Determines whether to print, download, or generate PDF.pdfData: The content and structure of the PDF.pdfConfig: Configuration options including page size, fonts, margins, and more.callback: Optional function that runs after the action is completed.
Usage
import { handlePdfAction, PdfConfig, PdfData } from '@the-serial-coder/pdf-schema';
const config: PdfConfig = {
pageSize: 'A4',
fontConfig: {
font: 'Roboto',
fontSize: 12,
color: '#000000',
bold: false,
italics: false
}
};
const data: PdfData = {
headers: [/* ... */],
content: [/* ... */],
footers: [/* ... */]
};
// Trigger PDF action
handlePdfAction('print', data, config);More Information
For full usage, advanced configuration, and examples, please visit the official documentation.
License
MIT
