Some parts of this article have been written with AI. Be aware that AI can make mistakes.
Applies to : PowerDocs for Linux PowerDocs for Windows

Class `PdfRenderer`

The PdfRenderer object is passed into the renderPdf(renderer, content, args) callback registered via Markdown.registerBlock(). It provides a fluent, declarative API to construct sophisticated QuestPDF visual elements for PDF exports and previews.


Properties

PdfRenderer does not expose public properties.


Methods

1. box(options, callback)

Creates a bordered, padded container or card.

Parameters

  • options (object): Styling properties for the box.
  • callback (function(boxRenderer)): Nested callback to render child elements inside the box.

Box Options

Option Type Default Description
backgroundColor string transparent Background color (HEX like '#ecfdf5' or named color like 'green').
borderColor string transparent Border color.
borderWidth number 0 Uniform border thickness in points.
borderLeftWidth number 0 Left border thickness (ideal for callout/alert strips).
borderRightWidth number 0 Right border thickness.
borderTopWidth number 0 Top border thickness.
borderBottomWidth number 0 Bottom border thickness.
cornerRadius number 0 Rounded corner radius in points.
padding number 0 Uniform inner padding.
paddingHorizontal number 0 Left and right inner padding.
paddingVertical number 0 Top and bottom inner padding.
marginTop number 0 Outer space above the box.
marginBottom number 0 Outer space below the box.

2. row(callback)

Creates a horizontal flex-style row layout.

Parameters

  • callback (function(rowRenderer)): Callback to add child items to the row.

Row Methods (rowRenderer)

  • badge(options): Adds a compact pill/badge to the row.
  • text(options): Adds text to the row.
  • spacing(width): Adds a fixed horizontal space (in points).
  • item(callback): Adds a relative flexible child block occupying remaining row width.

3. column(callback)

Creates a vertical nested column layout.

Parameters

  • callback (function(colRenderer)): Callback to add child items to the vertical column.

4. badge(options)

Renders a compact colored status pill or badge.

Badge Options

Option Type Default Description
text string '' Text displayed inside the badge.
backgroundColor string '#3b82f6' Background fill color.
textColor string '#ffffff' Text color.
fontSize number 9 Font size in points.
bold boolean true Whether the badge text is bold.
cornerRadius number 3 Rounded corner radius.

5. text(options)

Renders a paragraph or line of formatted text.

Text Options

Option Type Default Description
text string '' Text content to display.
color / fontColor string '#000000' Text color (HEX or named color).
fontSize number 10 Font size in points.
bold boolean false Bold font weight.
italic boolean false Italic font style.
underline boolean false Underline text decoration.
fontFamily string 'Segoe UI' Font family name (e.g. 'Consolas', 'Arial').

6. line(options)

Renders a horizontal separator line.

Line Options

Option Type Default Description
color string '#cbd5e1' Line color.
thickness number 1 Line height/thickness in points.
marginVertical number 4 Top and bottom margin around the line.

7. code(content, fontFamily, fontSize)

Renders a monospace code snippet block with subtle background and border styling.

Parameters

  • content (string): Monospace code text.
  • fontFamily (string, optional): Font family (defaults to 'Consolas').
  • fontSize (number, optional): Font size (defaults to 9.5).

Examples

Complex Multi-Element Card Layout

export function activate(context) {
    context.markdown.registerBlock({
        name: 'database-table',
        renderPdf: (renderer, content, args) => {
            const tableName = (args || 'Untitled Table').trim();

            renderer.box({
                backgroundColor: '#f8fafc',
                borderColor: '#cbd5e1',
                borderWidth: 1,
                cornerRadius: 6,
                padding: 10,
                marginTop: 8,
                marginBottom: 8
            }, (box) => {
                // Header row with badge and title
                box.row((row) => {
                    row.badge({ text: 'TABLE', backgroundColor: '#475569', textColor: '#ffffff', bold: true });
                    row.spacing(8);
                    row.text({ text: tableName, bold: true, fontSize: 11, color: '#0f172a' });
                });

                // Separator line
                box.line({ color: '#e2e8f0', thickness: 1, marginVertical: 6 });

                // Description text
                box.text({ text: (content || '').trim(), fontSize: 9.5, color: '#334155' });
            });
        }
    });
}