A specialized tool for converting Svelte and SvelteKit documentation into book-friendly PDF format. The tool extracts clean, readable content from the documentation websites and generates both individual page PDFs and combined comprehensive manuals.
npm install
Generate both Svelte and SvelteKit documentation with a single command:
node index.js docs
This command will:
Options:
-c, --combine
: Create combined PDFs (default: true)--no-extract
: Skip link extraction step and use existing link files--no-legacy
: Exclude Svelte legacy content--no-v4
: Exclude Svelte v4 migration guide--no-migration
: Exclude SvelteKit migration guides--svelte-dir <directory>
: Custom output directory for Svelte docs (default: 'svelte-docs')--sveltekit-dir <directory>
: Custom output directory for SvelteKit docs (default: 'sveltekit-docs')--svelte-name <filename>
: Custom name for the Svelte combined PDF (default: 'svelte-documentation.pdf')--sveltekit-name <filename>
: Custom name for the SvelteKit combined PDF (default: 'sveltekit-documentation.pdf')Generate the complete Svelte documentation as a combined PDF:
node index.js svelte -c
Options:
-c, --combine
: Create a combined PDF of all pages (recommended)-o, --output-dir <directory>
: Custom output directory (default: 'svelte-docs')--combined-name <filename>
: Custom name for the combined PDF (default: 'svelte-documentation.pdf')--no-legacy
: Exclude legacy content--no-v4
: Exclude v4 migration guideGenerate the complete SvelteKit documentation as a combined PDF:
node index.js sveltekit -c
Options:
-c, --combine
: Create a combined PDF of all pages (recommended)-o, --output-dir <directory>
: Custom output directory (default: 'sveltekit-docs')--combined-name <filename>
: Custom name for the combined PDF (default: 'sveltekit-documentation.pdf')--no-migration
: Exclude migration guidesTo update the links used for documentation generation:
node extract-links.js
This will:
svelte-links.js
and sveltekit-links.js
Generate complete Svelte ecosystem documentation (recommended):
node index.js docs --no-legacy
Generate modern Svelte documentation only:
node index.js svelte -c --no-legacy
Generate comprehensive SvelteKit guide:
node index.js sveltekit -c --combined-name sveltekit-guide.pdf
Generate both sets with different output directories:
node index.js docs --svelte-dir svelte --sveltekit-dir kit
Generate both Svelte and SvelteKit documentation:
node index.js svelte -c
node index.js sveltekit -c
When creating combined PDFs, the tool provides useful statistics including:
The tool uses Puppeteer for PDF generation, with all configuration options managed through the config.js
file. These settings control how your PDFs look and behave.
You can customize the following PDF properties:
pdf: {
format: 'A4', // Paper size: A4, Letter, Legal, Tabloid, etc.
landscape: false, // Orientation: false=portrait, true=landscape
scale: 0.7, // Scaling factor (0.7 = 70% of original size)
margin: { // Page margins in cm or inches
top: '1cm',
right: '1cm',
bottom: '1cm',
left: '1cm'
},
printBackground: true, // Whether to include background graphics/colors
// Advanced options (commented out by default in config.js)
// displayHeaderFooter: true, // Show header and footer
// headerTemplate: '<div>...</div>', // Custom HTML for header
// footerTemplate: '<div>...</div>', // Custom HTML for footer
// pageRanges: '1-5', // Specific pages to export
// tagged: true, // Generate tagged (accessible) PDF
// outline: true, // Include document outline
}
These options are passed directly to Puppeteer's page.pdf()
method. The full documentation for all available options can be found in the Puppeteer API documentation.
When using displayHeaderFooter: true
, you can customize the header and footer with HTML templates. These templates can include special classes:
pageNumber
- Current page numbertotalPages
- Total pages in the documentdate
- Current dateExample:
headerTemplate: '<div style="font-size: 10px; text-align: center;">Svelte Documentation</div>',
footerTemplate: '<div style="font-size: 10px; text-align: center;">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>'
Control where generated PDFs are saved:
output: {
defaultFileName: 'output.pdf', // Default name for single file output
defaultDirectory: 'output' // Default directory for bulk operations
}
The tool also supports general webpage-to-PDF conversion:
node index.js convert https://example.com -o output.pdf
node index.js bulk urls.txt -o output-directory -c
node index.js urls https://example.com https://another-example.com -c