Skip to content

Rendering Guide

This guide covers advanced rendering techniques with noto-pdf-ts.

Understanding Scale

The scale option controls the output resolution. PDFs are typically created at 72 DPI, so:

ScaleDPIUse Case
0.536Small thumbnails
1.072Original PDF size
1.5108Default, good balance
2.0144High quality viewing
3.0216Print quality
// Example: Generate thumbnails and high-res versions
const pdf = await openPdf('/path/to/document.pdf');
// Thumbnails
for await (const page of pdf.renderPages({ scale: 0.5 })) {
await fs.writeFile(`thumb-${page.pageNumber}.jpg`, page.buffer);
}
// High resolution
for await (const page of pdf.renderPages({ scale: 2.0, format: 'png' })) {
await fs.writeFile(`hires-${page.pageNumber}.png`, page.buffer);
}
await pdf.close();

Memory Efficiency

noto-pdf-ts uses async generators for memory-efficient processing:

// Memory efficient - processes one page at a time
for await (const page of pdf.renderPages()) {
await processPage(page);
// Previous page resources are released before next page
}

For very large PDFs, you can also process pages in batches:

const BATCH_SIZE = 10;
for (let i = 1; i <= pdf.pageCount; i += BATCH_SIZE) {
const endPage = Math.min(i + BATCH_SIZE - 1, pdf.pageCount);
for await (const page of pdf.renderPages({
pages: { start: i, end: endPage }
})) {
await processPage(page);
}
// Optional: pause between batches
await new Promise(resolve => setTimeout(resolve, 100));
}

Parallel Processing

While pages are rendered sequentially for memory efficiency, you can process the output in parallel:

const pages: RenderedPage[] = [];
for await (const page of pdf.renderPages()) {
pages.push(page);
}
// Process all pages in parallel
await Promise.all(
pages.map(page => fs.writeFile(`page-${page.pageNumber}.jpg`, page.buffer))
);

CJK Font Support

noto-pdf-ts provides built-in support for Chinese, Japanese, and Korean fonts through PDFium. CJK fonts are handled automatically without any additional configuration.

Rendering Single Pages

For rendering specific pages, use renderPage():

const pdf = await openPdf('/path/to/document.pdf');
// Render just the first page
const firstPage = await pdf.renderPage(1);
await fs.writeFile('cover.jpg', firstPage.buffer);
// Render the last page
const lastPage = await pdf.renderPage(pdf.pageCount);
await fs.writeFile('back.jpg', lastPage.buffer);
await pdf.close();

Output Dimensions

The rendered page dimensions depend on the PDF page size and scale:

for await (const page of pdf.renderPages({ scale: 2.0 })) {
console.log(`Page ${page.pageNumber}: ${page.width}x${page.height} pixels`);
// For an A4 PDF (595x842 points), this would be approximately 1190x1684 pixels
}