
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
typescript-pdf
Advanced tools
A modern TypeScript library for programmatic PDF generation with a declarative API
A TypeScript library for programmatic PDF generation with a declarative, widget-based API inspired by Flutter. Build complex PDF documents with type safety.
typescript-pdf v0.6.1 represents a mature PDF generation library:
npm install typescript-pdf
# or
pnpm add typescript-pdf
# or
yarn add typescript-pdf
Professional tables with borders, text overflow, and custom styling:

Built-in chart widgets for business reports and dashboards:

Automatic page breaks with headers, footers, and consistent formatting:

import { writeFile } from 'fs/promises';
import { Document, Txt, Container, Layout, PdfColor } from 'typescript-pdf';
const doc = new Document();
doc.addPage({
build: () => new Container({
decoration: {
color: PdfColor.fromHex('#f0f0f0ff'),
border: { width: 1, color: PdfColor.black },
borderRadius: BorderRadiusUtils.circular(4),
},
padding: Layout.EdgeInsets.all(20),
child: new Txt('Hello World!', {
style: { fontSize: 24, color: PdfColor.fromHex('#1976d2') }
})
})
});
const pdfBytes = await doc.save();
console.log('PDF data has been generated.');
// Save the generated PDF data to a file named 'hello-world.pdf'.
await writeFile('hello-world.pdf', pdfBytes);
console.log('✅ Successfully saved PDF to hello-world.pdf');
import { Document, MultiPage, Table, Txt, Container, DataUtils, Theme } from 'typescript-pdf';
const doc = new Document();
doc.addPage({
build: () => new MultiPage({
header: (pageNum, total) => new Txt(`Page ${pageNum} of ${total}`),
children: [
new Container({
child: new Txt('Q4 Financial Report', {
style: { fontSize: 28, fontWeight: Theme.FontWeight.Bold }
})
}),
new Table({
data: [
['Product', 'Revenue', 'Growth'],
['Product A', '$1.2M', '+15%'],
['Product B', '$980K', '+8%'],
['Product C', '$750K', '+22%']
],
columnWidths: [
DataUtils.columnWidths.flex(1),
DataUtils.columnWidths.flex(1),
DataUtils.columnWidths.flex(1)
],
borders: DataUtils.borders.all({ width: 1, color: PdfColor.fromHex('#333333') }),
headerStyle: { fontSize: 14, fontWeight: Theme.FontWeight.Bold, color: PdfColor.white }
})
]
})
});
const pdfBytes = await doc.save();
import { Document, Column, BarChart, LineChart, DataUtils, LineMarker } from 'typescript-pdf';
const salesData = DataUtils.createSeries('Sales', [
{ x: 'Q1', y: 1200 },
{ x: 'Q2', y: 1450 },
{ x: 'Q3', y: 1100 },
{ x: 'Q4', y: 1680 }
]);
const doc = new Document();
doc.addPage({
build: () => new Column({
children: [
new BarChart({
title: 'Quarterly Sales Performance',
series: [salesData],
width: 400,
height: 250
}),
new LineChart({
title: 'Growth Trend',
series: [salesData],
width: 400,
height: 200,
marker: LineMarker.Rectangle
})
]
})
});
const pdfBytes = await doc.save();
typescript-pdf uses a sophisticated dual-layer architecture:
┌─────────────────────────────────────────────────────────────┐
│ Declarative Widget API │
│ ┌─────────────┐ ┌───────────────┐ ┌───────────┐ │
│ │ Layout │ │ Data │ │ Theme │ │
│ │ Widgets │ │ Visualization │ │ System │ │
│ └─────────────┘ └───────────────┘ └───────────┘ │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ PDF Generation Core │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Font │ │ Graphics │ │ Document │ │
│ │ System │ │ Context │ │ Management │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘
Container - Box model container with padding, margin, decorationPadding - Add spacing inside widgetsMargin - Add spacing outside widgetsAlign - Position child widgets with precise alignmentCenter - Quick center alignmentStack - Layer widgets with z-index positioningPositioned - Absolute positioning within StackRow - Horizontal flex layout with alignment optionsColumn - Vertical flex layout with distribution controlFlexible - Responsive flex childrenExpanded - Fill available space in flex layoutsTxt - Styled text rendering with font fallbacksRichText - Multi-span text with different stylesTable - Advanced tables with column layouts and bordersTableRow - Individual table rows with custom stylingBarChart - Horizontal and vertical bar chartsLineChart - Line graphs with markers and stylingChart - Base chart class for custom visualizationsMultiPage - Automatic page breaks with headers/footersTheme - Consistent styling across documentsDefaultTextStyle - Cascading text style inheritanceany types)# Clone and setup
git clone https://github.com/nick-we/typescript-pdf.git
cd typescript-pdf
pnpm install
# Development
pnpm dev # Start development server
pnpm test # Run test suite (267/267 tests)
pnpm test:ui # Visual test interface
pnpm build # Production build
pnpm type-check # TypeScript validation
Current Phase: Production Ready ✅
We welcome contributions! typescript-pdf has achieved production stability with comprehensive test coverage.
git checkout -b feature/amazing-featurepnpm test && pnpm type-check && pnpm lintany types allowed - maintain complete type safetyThis project is licensed under the MIT License - see the LICENSE file for details.
Made by Nick Westendorf
typescript-pdf v0.6.1 - PDF Generation for TypeScript
FAQs
A modern TypeScript library for programmatic PDF generation with a declarative API
The npm package typescript-pdf receives a total of 8 weekly downloads. As such, typescript-pdf popularity was classified as not popular.
We found that typescript-pdf demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.