core.medplumclientoptions.createpdf | Medplum

MedplumClientOptions.createPdf property [​](/content/docs/sdk/core.medplumclientoptions.createpdf#medplumclientoptionscreatepdf-property "Direct link to MedplumClientOptions.createPdf property"/index.html)

Create PDF implementation.

Default is none, and PDF generation is disabled.

Signature:

createPdf?: CreatePdfFunction;

Example 1 [​](/content/docs/sdk/core.medplumclientoptions.createpdf#example-1 "Direct link to Example 1"/index.html)

In browser environments, import the client-side pdfmake library.

<script src="pdfmake.min.js"></script>

<script>

async function createPdf(docDefinition, tableLayouts, fonts) {

return new Promise((resolve) => {

pdfMake.createPdf(docDefinition, tableLayouts, fonts).getBlob(resolve);

});

}

</script>

Example 2 [​](/content/docs/sdk/core.medplumclientoptions.createpdf#example-2 "Direct link to Example 2"/index.html)

In Node.js applications:

import type { CustomTableLayout, TDocumentDefinitions, TFontDictionary } from 'pdfmake/interfaces';

function createPdf(

docDefinition: TDocumentDefinitions,

tableLayouts?: { [name: string]: CustomTableLayout },

fonts?: TFontDictionary
): Promise<Buffer> {

return new Promise((resolve, reject) => {

const printer = new PdfPrinter(fonts ?? {});

const pdfDoc = printer.createPdfKitDocument(docDefinition, { tableLayouts });

const chunks: Uint8Array[] = [];

pdfDoc.on('data', (chunk: Uint8Array) => chunks.push(chunk));

pdfDoc.on('end', () => resolve(Buffer.concat(chunks)));

pdfDoc.on('error', reject);

pdfDoc.end();

});
}