Skip to main content

Quick Start for Node.js

NodeJS

Both wkhtmltopdf and Puppeteer are well-supported in Node.js, though they can be complex to configure for specific needs. Our PDF generation API provides a quicker, easier way to generate PDFs from HTML, URLs, and dynamic templates. Here's how to start in Node.js.

1. Get Your API Key

  • After registering, log in to the Admin Dashboard and navigate to the API Keys section to retrieve your API key.
  • Ensure you keep this key secure, as it is essential for authorizing your requests to the PDFBolt API.

2. Make Your First Request

Follow these examples below to send basic requests to the PDFBolt API and generate your PDFs effortlessly.

Choose your preferred endpoint and source combination.

➡️ Endpoints:

The Direct endpoint provides immediate PDF generation and returns the raw PDF file in the response.


➡️ Sources:

Convert any webpage into a PDF:

const fs = require('fs');

async function generatePdf() {
const response = await fetch('https://api.pdfbolt.com/v1/direct', {
method: 'POST',
headers: {
'API-KEY': 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: 'https://example.com',
format: 'A4',
printBackground: true
})
});

if (!response.ok) {
const errorText = await response.text();
throw new Error(`HTTP ${response.status} - ${errorText}`);
}

const pdfBuffer = await response.arrayBuffer();
fs.writeFileSync('webpage.pdf', Buffer.from(pdfBuffer));
console.log('PDF generated successfully');
}

generatePdf().catch(console.error);

3. What's next?

Continue your journey with PDFBolt by exploring its powerful features and benefits. Start by checking the available API Endpoints and dive into the Conversion Parameters to customize your integration for your unique needs.