ReLaXed
ReLaXed copied to clipboard
Possible to get access to pdf bytestream?
I'm going to be leveraging relaxedjs through a microservice, If possible I would like to avoid having to save a pdf file, serve it up, and then delete it. If relaxed could also return the byestream so that I could serve it from a URL, that would be great.
EDIT: just for some context I found that there is a <Promise<Buffer>> method here https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions
Ok. Quick question though: what is your use case and why not use puppeteer directly ?
@Zulko My goal was to store the pug design file on my rest service, and when requests were made providing certain data, relaxed would template that data across my pug design file and return the pdf buffer for me to pipe back in the response. Would puppeteer be better suited for that?
Yes, the puppeteer code is very simple and will have the advantage that you won't start a new chromium instance at each request. See that approximative snippet below (you will have to google a bit, I am not sure about the exact names of the methods):
// create a Chromium "page" once at server start:
const browser = await puppeteer.launch();
const page = await browser.newPage();
// in your request handler:
var html = pug.parse("my_template.pug", request.parameters)
await page.setHTML(html, {waitUntil: 'networkidle2'});
var pdfBuffer = await page.pdf({format: 'A4'});
ReLaXed provides some advantages like plugins for mathjax support and other goodies, but most features are oriented for interactive use.
@Zulko thank you! Sounds good