Express API that will use Puppteer to create a PDF for a given URL
- Clone the repo
- Rename .env.example to
.env
and add in API user & key - run
npm install
npm run dev-server
which will start nodemon
POST to:
/api/v1/pdf
Format of POST:
{
"renderer": "puppeteer",
"htmlURL": "http://www.google.co.uk",
"pdfOptions" : {
"width": "595",
"height": "842"
}
}
You'll need to provide HTTP basic auth details.
Example POSTMAN request can be found in the postman directory: POSTMAN file to import
Testing implemented using supertest & mocha, run using npm test
- controllers/pdfController
- generateTimeStampFileName
- puppeteerPDF
- phantomPDF
- generatePDF
- config/auth
- config/users
- findByUsername
- schemas/requestSchema
- controllers/errorController
PDF Controller handles generating PDFs
returns a string based on the current date/time
Returns String fileName
Creates a PDF for a given URL using Puppeteer and returns a binary file inside a buffer
htmlURL
String a public URL to the HTML you wish to convertpdfOptions
Object optional settings for PDF generation (optional, default{width:595,height:842}
)
Returns Buffer buffer
This function shouldn't be used No need for phantom PDF rendering
Meta
- deprecated: This is deprecated.
picks up the JSON posted from the API and triggers rendering the PDF via the specified renderer
req
Express.Requestres
Express.Response
Auth module Passport auth related functionality
Users db module
searches the users object to match the username sent via the http request
username
the username sent from the http authcb
unsure what this does - the perils of copying code off the internet - assume this is a callback function?
schemas/requestSchema.js Example valid JSON for requestSchema
{
"renderer": "puppeteer",
"htmlURL": "http://www.google.co.uk",
"pdfOptions" : {
"width": 100,
"height": 100
}
}
Error Controller handles sending errors back to the client