> ## Documentation Index
> Fetch the complete documentation index at: https://learn.nextedy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PDF Export Template

> The PDF export template (`risksheetPdfExport.vm`) generates a JavaScript export script that controls how Nextedy RISKSHEET data is exported to PDF documents.

export const LastReviewed = ({date}) => {
  if (!date) return null;
  const formatted = new Date(`${date}T00:00:00Z`).toLocaleDateString("en-US", {
    year: "numeric",
    month: "long",
    day: "numeric",
    timeZone: "UTC"
  });
  return <p className="mt-10 text-sm text-gray-400 dark:text-zinc-500 not-prose">
      Last reviewed on {formatted}
    </p>;
};

## Export Pipeline

<Frame>
  <img src="https://mintcdn.com/none-17b4493f/yWl5nA2D0IzEnZC1/risksheet/diagrams/reference/templates/pdf-export-template/diagram-1.svg?fit=max&auto=format&n=yWl5nA2D0IzEnZC1&q=85&s=681086a66c2460dc3ee16160dc5b23ba" alt="diagram" style={{ maxWidth: "540px", width: "100%" }} width="540" height="400" data-path="risksheet/diagrams/reference/templates/pdf-export-template/diagram-1.svg" />
</Frame>

## Template Location

| Property            | Value                                  |
| ------------------- | -------------------------------------- |
| Default file name   | `risksheetPdfExport.vm`                |
| Attachment location | Polarion document or template document |
| Endpoint            | `/api/pdfscript`                       |
| Requires            | `revision` parameter                   |

The template follows the same inheritance hierarchy as sheet configuration. If no `risksheetPdfExport.vm` is attached to the current document, Risksheet searches the template hierarchy. See [Template Path Configuration](/risksheet/reference/configuration/template-path-configuration).

## Configuration Properties

| Name                     | Type      | Default                 | Description                                                            |
| ------------------------ | --------- | ----------------------- | ---------------------------------------------------------------------- |
| `risksheetPdfExport.vm`  | `string`  | `risksheetPdfExport.vm` | Name of the Velocity template file for PDF export                      |
| `pdfExportConfiguration` | `string`  | See application         | Full content of the rendered PDF export template                       |
| `templateName`           | `string`  | `null`                  | Name of the template used when configuration is loaded from a template |
| `fromTemplate`           | `boolean` | `false`                 | Whether the PDF export configuration was loaded from a template        |
| `configPath`             | `string`  | `null`                  | Path to the sheet configuration that was loaded                        |

## Export Script Scope Variables

The rendered JavaScript export script has access to these scope variables:

| Variable          | Type          | Description                                                |
| ----------------- | ------------- | ---------------------------------------------------------- |
| `exporter`        | `ExportToPdf` | Main export engine with methods for generating PDF content |
| `PDFExport`       | `object`      | PDF generation library                                     |
| `GridPDF`         | `object`      | Grid-to-PDF rendering engine                               |
| `isInCompare`     | `boolean`     | Whether the export is running in comparison mode           |
| `compareRevision` | `string`      | Revision being compared against (if in comparison mode)    |
| `currentRevision` | `string`      | Current document revision                                  |
| `showUnchanged`   | `boolean`     | Whether to include unchanged rows in comparison export     |

## Export Methods

### exportMainSheet

Exports the primary Risksheet grid to PDF.

| Parameter     | Type     | Description                                                    |
| ------------- | -------- | -------------------------------------------------------------- |
| `hideColumns` | `string` | Comma-separated binding names of columns to hide during export |

```javascript theme={null}
// Export full grid
exporter.exportMainSheet();

// Export grid with specific columns hidden
exporter.exportMainSheet("internalNotes,debugColumn");
```

Columns specified in `hideColumns` are temporarily hidden during export and restored after PDF generation.

### exportSubTable

Exports a filtered sub-grid containing only rows where the specified control column has non-empty values.

| Parameter       | Type     | Description                        |
| --------------- | -------- | ---------------------------------- |
| `controlColumn` | `string` | Column binding used to filter rows |

```javascript theme={null}
// Export mitigation tasks sub-table
exporter.exportSubTable("mitigationTask");
```

### exportDownstreamTable

Exports downstream traceability tables with deduplication based on control column values.

| Parameter       | Type     | Description                         |
| --------------- | -------- | ----------------------------------- |
| `controlColumn` | `string` | Column binding for downstream items |

```javascript theme={null}
// Export unique downstream verification activities
exporter.exportDownstreamTable("verificationActivity");
```

The deduplication logic tracks processed values to show each unique downstream relationship once.

### exportRatingTable

Exports risk rating definition tables with three columns: ID, Label, and Description.

| Parameter  | Type     | Description                                                                                                                                      |
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `ratingId` | `string` | Enumeration ID of the rating scale to export; matches the `<enumId>` of a `rating:<enumId>` column type, which references a Polarion enumeration |

```javascript theme={null}
// Export severity rating definitions
exporter.exportRatingTable("severity");

// Export occurrence rating definitions
exporter.exportRatingTable("occurrence");
```

### exportEnumTable

Exports enumeration value tables showing ID, Label, and Description.

| Parameter | Type     | Description                                                                                                                                         |
| --------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `enumId`  | `string` | Enumeration ID to export; matches the `<enumId>` of an `enum:<enumId>` or `multiEnum:<enumId>` column type, which references a Polarion enumeration |

```javascript theme={null}
// Export risk category enum values
exporter.exportEnumTable("riskCategory");
```

### exportCustomTableData

Exports arbitrary tabular data with custom column definitions.

| Parameter | Type     | Description                                          |
| --------- | -------- | ---------------------------------------------------- |
| `data`    | `array`  | Array of row objects                                 |
| `columns` | `array`  | Column definitions with `binding`, `header`, `width` |
| `xpos`    | `number` | Optional horizontal position                         |
| `ypos`    | `number` | Optional vertical position                           |

```javascript theme={null}
exporter.exportCustomTableData(
  [{ item: "Safety Goal 1", status: "Open", priority: "High" }],
  [
    { binding: "item", header: "Item", width: 200 },
    { binding: "status", header: "Status", width: 100 },
    { binding: "priority", header: "Priority", width: 100 }
  ]
);
```

## Cell Formatting in PDF

The PDF export engine handles different column types automatically:

| Column Type          | PDF Rendering                        |
| -------------------- | ------------------------------------ |
| Multi-enum           | Comma-separated text values          |
| Item link            | Label property text                  |
| Server-rendered HTML | Stripped to plain text               |
| Boolean              | Checkbox representation              |
| Empty cells          | Configurable `emptyPlaceholder` text |

<Warning title="Enum Display Inconsistency">
  Regular enum fields export with display titles, but rating fields (numeric IDs) and user reference fields may export with IDs instead of display names. Use saved views as an alternative for consistent formatting.
</Warning>

## Export Properties

| Name               | Type      | Default         | Description                                                      |
| ------------------ | --------- | --------------- | ---------------------------------------------------------------- |
| `emptyPlaceholder` | `string`  | `null`          | Text to display in PDF for null or empty cells                   |
| `mergeCacheFlag`   | `boolean` | See application | Affects how merged cells render in PDF export                    |
| `masterMergeOnly`  | `boolean` | See application | Controls PDF table structure (flat vs. hierarchical row merging) |

## Validation Requirements

PDF export requires a clean document state:

* Export is blocked if the sheet has unsaved changes (`isDirty()` returns `true`)
* Export is blocked when comparison mode is active
* Save the document before exporting to ensure the PDF reflects a consistent state

A progress notification displays during PDF generation with the message "Exporting to PDF - Please wait while the file is being generated."

## Multi-Page Behavior

<Note title="Page Break Behavior">
  When risk items span multiple pages, text from linked elements (hazard, hazardous situation, harm) may repeat on the next page for context. This is by design but can be interpreted as duplicate entries by reviewers. Cell height calculation may truncate text for linked elements in some cases.
</Note>

### Images on Multiple Pages

The `doc.pageAdded` event only applies to the page where it is called. To display a logo or header image on every page, call `doc.pageAdded` after each `#newPage()` invocation. It does not automatically repeat for table overflow pages.

```velocity theme={null}
// Add header to first page
doc.pageAdded(function() {
  // Draw logo/header
});

// After explicit page break
#newPage()
doc.pageAdded(function() {
  // Must re-add for this page
});
```

## Complete Example

```velocity theme={null}
## risksheetPdfExport.vm - FMEA PDF Export

#set($docTitle = $doc.moduleNameWithSpace)
#set($revision = $request.getParameter("revision"))

<script>
  // Cover page
  doc.header("FMEA Report: ${docTitle}");
  doc.subheader("Revision: ${revision}");

  // Main risk table
  exporter.exportMainSheet("internalNotes");

  // Rating definitions
  #newPage()
  doc.header("Rating Definitions");
  doc.subheader("Severity Scale");
  exporter.exportRatingTable("severity");

  doc.subheader("Occurrence Scale");
  exporter.exportRatingTable("occurrence");

  doc.subheader("Detection Scale");
  exporter.exportRatingTable("detection");

  // Mitigation tasks
  #newPage()
  doc.header("Mitigation Tasks");
  exporter.exportSubTable("mitigationTask");
</script>
```

## Related Pages

* [PDF Export API](/risksheet/reference/api/pdf-export-api) -- programmatic export interface
* [Velocity Template Context](/risksheet/reference/api/velocity-context) -- available context variables
* [Velocity Templates](/risksheet/reference/templates/velocity-templates) -- template engine reference
* [Top Panel Template](/risksheet/reference/templates/top-panel-template) -- top panel customization

<LastReviewed date="2026-06-24" />
