When you callDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/bpampuch/pdfmake/llms.txt
Use this file to discover all available pages before exploring further.
pdfmake.createPdf(docDefinition), pdfmake returns an OutputDocument object that wraps a lazy PDF generation pipeline. The actual rendering work begins the first time you call an output method. All output methods return a Promise. The internal buffer is computed once and cached — subsequent calls to getBuffer(), getBase64(), or getDataUrl() on the same instance reuse the cached result without re-rendering.
Getting an OutputDocument
The buffer cache applies to
getBuffer(), getBase64(), and getDataUrl() — these all share a single internally computed bufferPromise. getStream() and write() operate on the raw PDFKit stream and are not cached. Do not call both getBuffer() and write() on the same OutputDocument instance; getBuffer() internally calls stream.end(), which will interfere with write().Shared Methods
These methods are available in both the Node.js and browser builds. They inherit from theOutputDocument base class.
getStream()
Returns thePromise that resolves to the underlying PDFKit document stream. This is the lowest-level escape hatch; prefer getBuffer() unless you need to pipe the stream directly.
getBuffer()
Collects all PDF stream chunks and resolves with a single concatenatedBuffer containing the complete PDF binary. The result is cached internally — subsequent calls on the same instance return the same promise without re-rendering.
getBase64()
Resolves with the complete PDF encoded as a base64 string. Internally callsgetBuffer() and then runs .toString('base64') on the result.
getDataUrl()
Resolves with a completedata: URL string in the form data:application/pdf;base64,<encoded-pdf>. Internally calls getBase64() and prepends the MIME prefix.
Node.js Methods
The following method is available only in the Node.js build (
OutputDocumentServer). It is not present in the browser bundle.write()
Writes the PDF to the local file system at the given path. Internally pipes the PDFKit stream into afs.WriteStream and waits for both the source stream and the write stream to close cleanly.
The destination file path. Relative paths are resolved from the current working directory of the Node.js process. The directory must already exist;
write() does not create intermediate directories.Browser Methods
The following methods are available only in the browser build (
OutputDocumentBrowser). They rely on browser-specific APIs such as Blob, URL.createObjectURL, and the file-saver library.getBlob()
Resolves with aBlob of type application/pdf containing the full PDF binary. Internally calls getBuffer() and wraps the result in new Blob([buffer], { type: 'application/pdf' }).
download()
Triggers a browser file-save dialog using thefile-saver library, offering the PDF as a download to the user.
The suggested file name for the download. Defaults to
'file.pdf' if omitted.open()
Opens the PDF in a new browser window or tab. pdfmake must open the window synchronously (before the async PDF generation begins) to avoid popup blockers, so it callswindow.open() immediately and navigates the window to the blob URL once the PDF is ready.
An existing
Window reference to navigate. If null or omitted, pdfmake opens a new window with window.open('', '_blank'). Pass a pre-opened window when you need to control the window before the PDF is ready.print()
Opens the PDF in a browser window and immediately triggers the browser’s native print dialog. Internally callsstream.setOpenActionAsPrint() on the PDFKit document to embed a print-on-open action, then delegates to open().
An existing
Window reference, behaving identically to the win parameter of open(). If null or omitted, a new window is opened.Method Summary
- Node.js
- Browser
| Method | Returns | Description |
|---|---|---|
getStream() | Promise<object> | Raw PDFKit document stream |
getBuffer() | Promise<Buffer> | Full PDF as a Node.js Buffer |
getBase64() | Promise<string> | Full PDF as a base64 string |
getDataUrl() | Promise<string> | Full PDF as a data: URL |
write(filename) | Promise<void> | Write PDF to local file |