This folder contains comprehensive examples demonstrating all features and options of the AFPP library.
Before running the examples, make sure to build the library:
npm run buildExamples import from the compiled dist/ folder. If you change source files, re-run the build.
Run any example from the repository root:
npx tsx examples/01-basic-text-extraction.ts| Example | Description |
|---|---|
| 01-basic-text-extraction.ts | Simple text extraction using pdf2string |
| 02-input-types.ts | Different input types: file path, Buffer, Uint8Array, URL |
| 03-encrypted-pdf.ts | Handling password-protected PDFs |
| 04-basic-image-rendering.ts | Rendering PDF pages as images using pdf2image |
| 05-image-encoding-formats.ts | Image formats: PNG, JPEG, WebP, AVIF |
| 06-concurrency.ts | Parallel processing with the concurrency option |
| 07-scale-options.ts | Image resolution control with the scale option |
| 08-parse-pdf-callback.ts | Advanced usage with parsePdf and custom callbacks |
| 09-error-handling.ts | Error handling patterns and edge cases |
| 10-all-options-combined.ts | Production configurations combining all options |
Extracts text content from all pages of a PDF.
const pages = await pdf2string('document.pdf');Renders all PDF pages as images.
const images = await pdf2image('document.pdf');Low-level API for custom page-by-page processing.
const results = await parsePdf(
'document.pdf',
{},
(content, pageNum, pageCount) => {
return typeof content === 'string' ? content.length : content.byteLength;
},
);All functions accept the following input types:
string- Local file pathBuffer- Node.js Buffer containing PDF dataUint8Array- Typed array with PDF bytesURL- Remote PDF URL
| Option | Type | Default | Description |
|---|---|---|---|
password |
string |
- | Password for encrypted PDFs |
concurrency |
number | 'auto' |
1 |
Number of pages processed in parallel. Use 'auto' for CPU-based scaling. |
scale |
number |
1 |
Image rendering resolution. Valid range: 0.1–10. (1.0 = 72 DPI, 2.0 = 144 DPI, 3.0 = 216 DPI) |
imageEncoding |
'png' | 'jpeg' | 'webp' | 'avif' |
'png' |
Output image format |
Examples that generate files (images, etc.) save them to the examples/output/ directory. This directory is automatically created when running examples and is excluded from git.
The examples use test PDFs from the test/ folder:
example.pdf- Standard text-based PDF (9 pages)example-encrypted.pdf- Password-protected PDF (password:example)example-img.pdf- Image-heavy PDF (9 pages)