@optimiser/offload
v1.0.3
Published
Utility functions of optimiser offload server.
Downloads
9
Readme
@optimiser/offload
The @optimiser/offload
library simplifies PDF generation from HTML strings by utilizing a dedicated offload server. This approach ensures efficient PDF creation with options for handling the response as either a buffer or a stream.
Installation
Add @optimiser/offload
to your project using npm or Yarn:
npm install @optimiser/offload
or
yarn add @optimiser/offload
Usage
The generatePDF
function allows posting HTML to an offload server for PDF conversion. You can specify the response type as either a buffer or a stream.
Basic Example
const { generatePDF } = require('@optimiser/offload');
async function createPDF() {
const config = {
html: '<h1>Title</h1><p>This is your HTML content.</p>',
options: {}, // Puppeteer options, if any
responseType: 'buffer' // Choose 'buffer' or 'stream'
};
try {
const pdfData = await generatePDF(config);
console.log('PDF generated successfully!');
// Handle the PDF data (buffer or stream)
} catch (error) {
console.error('Error generating PDF:', error);
}
}
createPDF();
Configuration Options
html
: Your HTML string for PDF generation.options
: Optional. Puppeteer configuration for PDF generation.responseType
: Specify 'buffer' or 'stream' for your output format. Default is 'buffer'.
Make sure to set the OFFLOAD_SERVER_ENDPOINT
environment variable(.env) to your offload server's URL.