What This Adds In Cloud Code
- Server-side PDF rendering as base64 output.
- Supports HTML or URL input.
- Built-in URL/reference safety checks.
Quick Start
js
const PDF = require('pdf');
const pdfBase64 = PDF.render('<html><body><h1>Invoice</h1></body></html>');API
| Function | Params | Returns | Notes |
|---|---|---|---|
render(htmlOrUrl, options) | string + optional rendering options | string | Returns base64 PDF content. |
Practical Example
js
const PDF = require('pdf');
const Mail = require('mail');
const invoicePdf = PDF.render(`<html><body><h1>Invoice #${request.params.order_no}</h1></body></html>`);
Mail.send({
to: request.params.email,
subject: 'Your invoice',
text: 'Attached invoice.',
attachments: {
'invoice.pdf': invoicePdf
}
});Failure Modes & Gotchas
- Unsafe URLs/embedded references are rejected.
- Large/complex HTML can increase render time.