Use this package when code needs to render HTML to a PDF through the Puppet Master server.
- Install:
npm install @codebucket/puppet-master - Import:
import { PuppetMaster } from "@codebucket/puppet-master";
This package currently exposes one public method only:
new PuppetMaster({
baseUrl: string,
apiKey: string,
})
await client.pdf({
pdfPath: string,
content: string,
launchOptions?: Record<string, unknown>,
pageOptions?: Record<string, unknown>,
pdfOptions?: Record<string, unknown>,
otherPageFunctions?: Array<
[methodName: string] | [methodName: string, args: unknown[]]
>,
})- Always pass
baseUrlandapiKeywhen constructing the client. - Always pass both
pdfPathandcontentwhen callingpdf. - Treat
pdfPathas a local output path only. It is not part of the server task payload. - Treat
launchOptions,pageOptions, andpdfOptionsas pass-through Puppeteer option objects. - Model
otherPageFunctionsas an ordered tuple array of page method calls.
The client sends:
{
"task": {
"content": "<html>...</html>",
"launchOptions": {},
"pageOptions": {},
"pdfOptions": {},
"otherPageFunctions": [
["waitForNetworkIdle", [{ "idleTime": 500 }]]
]
}
}The client also sends the x-api-key header.
- Do not invent extra public methods.
- Do not model
otherPageFunctionsas an object. - Do not call the server directly if this package is already available.
- Prefer the exported
PuppetMasterClientOptions,RemotePdfTaskOptions,PdfTaskOptions, andPageFunctionCalltypes in TypeScript.
- The uploaded server currently executes
otherPageFunctionsafterpage.pdf(). Do not rely on those calls to affect the generated PDF unless the server implementation changes.