A Node.js tool for converting GitBook documentation pages into PDF files. Supports multiple URLs and customizable output settings.
- Node.js version 14.0.0 or higher
- NPM (Node Package Manager)
- Minimum 500MB free disk space (for Playwright and Chromium)
- Stable internet connection
- Visit Node.js official website
- Download and install the LTS (Long Term Support) version
- Verify installation:
node --version
npm --version# Create project directory
mkdir gitbook-spider
cd gitbook-spider
# Initialize Node.js project
npm init -y # Install Playwright
npm install playwright
# Install Playwright browsers
npx playwright install chromiumCreate and set up the following files:
config.json- Configuration settings:
{
"siteConfig": {
"chapterLinksElmSelector": "nav a",
"bodySelector": "main",
"bookContentSelector": "main",
"headerSelector": "header",
"navNextSelector": "nav",
"sideBarSelector": "aside"
},
"browserConfig": {
"headless": false,
"timeout": 60000
},
"pdfConfig": {
"format": "A4",
"margin": {
"top": "50px",
"bottom": "50px",
"left": "50px",
"right": "50px"
}
},
"books": [
{
"url": "https://your-gitbook-url.com",
"title": "YourBookTitle"
}
],
"outputDir": "./output"
}- Copy the contents of
pdfSpider.jsandindex.jsto their respective files.
Update the books array in config.json:
"books": [
{
"url": "https://docs.twgamesdev.com/uhfps/guides/managing-inputs",
"title": "ManagingInputs"
},
{
"url": "https://your-second-url.com",
"title": "SecondBook"
}
]node index.jsPDF files will be generated in the output/ directory.
Modify Config in config.json:
"Config": {
"format": "A4", // A4, Letter, Legal...
"margin": {
"top": "50px",
"bottom": "50px",
"left": "50px",
"right": "50px"
}
}"browserConfig": {
"headless": false, // true for no GUI
"timeout": 60000 // in milliseconds
}