Skip to main content

PDF Export Context

PDF export scripts are executed with access to a rich context object containing document information, grid settings, and utility functions:
## Access the RISKSHEET document
$document.name          ## Document title
$document.revision      ## Current revision number
$document.created       ## Creation timestamp

## Access grid configuration
$gridSettings.columns   ## Column definitions
$gridSettings.data      ## Grid row data

## Use PDF utilities
$exporter.addTable()    ## Export grid as table
$exporter.addPage()     ## Insert page break

Context Variables

Document Context

VariableTypeDescription
$document.namestringRISKSHEET document title
$document.revisionintegerCurrent document revision
$document.createddateDocument creation timestamp
$document.modifieddateLast modification timestamp
$document.authorstringDocument creator username
$document.projectstringPolarion project key
$document.pathstringRepository document path
$document.baselinesarrayAssociated baselines (if any)

Grid Configuration

VariableTypeDescription
$gridSettings.columnsarrayColumn definitions and bindings
$gridSettings.dataarrayRow data as JSON objects
$gridSettings.selectedRowsarrayCurrently selected row indices
$gridSettings.hiddenColumnsarrayColumns hidden during export
$gridSettings.rowCountintegerTotal number of rows
$gridSettings.columnCountintegerTotal number of columns

Export State

VariableTypeDescription
$isInComparebooleanTrue if comparing two revisions
$compareRevisionintegerBaseline revision for comparison
$currentRevisionintegerCurrent revision being exported
$showUnchangedbooleanInclude unchanged items in comparison

Exporter Methods

Main Grid Export

$exporter.exportMainSheet(
  $gridSettings,
  $hideColumns,
  $emptyPlaceholder
)
ParameterTypeDescription
gridSettingsobjectGrid configuration and data
hideColumnsstringComma-separated list of bindings to hide
emptyPlaceholderstringText to display for null/empty cells

Sub-Table Export

$exporter.exportSubTable(
  $gridSettings,
  $controlColumn,
  $title
)
Exports nested tables based on control column values. Filters to rows with non-empty control column values.
ParameterTypeDescription
gridSettingsobjectGrid configuration
controlColumnstringColumn binding for grouping
titlestringSubtitle for the sub-table

Downstream Table Export

$exporter.exportDownstreamTable(
  $gridSettings,
  $controlColumn,
  $title
)
Exports traceability tables with deduplication based on control column unique values.
ParameterTypeDescription
gridSettingsobjectGrid configuration
controlColumnstringColumn to deduplicate on
titlestringTable section title

Table Formatting Methods

MethodReturnsDescription
$exporter.exportRatingTable($ratingId)PDF tableRenders rating scale definitions
$exporter.exportEnumTable($enumId)PDF tableRenders enumeration value definitions
$exporter.addPage()voidInserts page break
$exporter.addText($text, $fontSize, $bold)voidAdds formatted text
$exporter.addHeading($text, $level)voidAdds heading (level 1-6)

Cell Type Rendering

Different cell types are automatically formatted for PDF export:

Text and Numeric Cells

Rendering: Plain text as-is
Alignment: Left-aligned by default
Formatting: Preserves styling (bold, italic, color)

Boolean Cells (Checkboxes)

## Renders as: true or false text
$isBoolean = true
## Output: "true" or "false" in cell
## Renders linked item text (not link itself)
## Example: "REQ-1234: User Authentication"
## Input: <a href="#">REQ-1234: User Authentication</a>
## Output: "REQ-1234: User Authentication"
## Parses JSON array of linked items
## Input: [{"id": "REQ-1", ...}, {"id": "REQ-2", ...}]
## Output:
## REQ-1: Requirement 1
## REQ-2: Requirement 2
## (newline-separated list)

## New unsaved items prefixed with asterisk (*)
## Input: {"id": "*temp-1"}
## Output: "*New Item"

Server-Rendered HTML Cells

## Strips HTML tags, preserves text content
## </li> converted to newline for proper list rendering
## Input: <ul><li>Item 1</li><li>Item 2</li></ul>
## Output:
## Item 1
## Item 2

Multi-Enum Cells

## Converts numeric enum IDs to readable labels
## Input: [1, 3, 5]  (enum value IDs)
## Output: "Critical, High, Medium"  (enum labels)
## Separator: Comma-separated with space

Styling and Formatting

Cell Styles

CSS styling from the web interface is automatically transferred to PDF cells:
CSS PropertyPDF EquivalentNotes
background-colorCell backgroundPreserved from grid
colorText colorPreserved from grid
text-align: leftLeft alignmentDefault
font-weight: boldBold textTransferred if set
font-style: italicItalic textTransferred if set

Style Selectors

/* Target most grid cells */
.inner-cell {
  background-color: #f0f0f0;
  color: #333333;
}

/* Fallback for special cells */
.wj-cell {
  background-color: #ffffff;
  color: #000000;
}

Row Height and Column Width

## Automatic row height calculation
## Rows expand to fit multi-line content

## Manual sizing in Velocity script
## Example: 60pt width for narrow column
## Example: 3x flexible width for wide column

Empty Cell Handling

Null or empty cells can display placeholder text:
## Set empty cell placeholder (default: blank)
#set($emptyPlaceholder = "N/A")

$exporter.exportMainSheet(
  $gridSettings,
  "",
  $emptyPlaceholder
)

## Result: Empty cells show "N/A" in PDF

Page Layout Configuration

Default Layout

SettingValueDescription
OrientationLandscapeWide page orientation
Paper SizeA4Standard ISO 216 A4
Top Margin26ptHeader spacing
Bottom Margin26ptFooter spacing
Left Margin26ptSide spacing
Right Margin26ptSide spacing

Multi-Page Handling

## Export main table (may span multiple pages)
$exporter.exportMainSheet($gridSettings, "", "")

## Important: Re-apply page event handlers after #newPage()
## Page headers are NOT inherited automatically

#set($doc.pageAdded)
  $drawImage("header-image.png")
#end

$exporter.addPage()

## Must re-apply handler after page break
#set($doc.pageAdded)
  $drawImage("header-image.png")
#end

Page Event Handlers

Page Added Event

#set($doc.pageAdded)
  ## Executed after each new page is created
  ## Useful for headers, footers, background images
  $drawImage("document-header.png", 0, 0, 800, 50)
#end
Page event handlers do NOT persist automatically across #newPage() breaks. You must reapply the handler after each page break if you want headers/footers/images on subsequent pages.

Example: Multi-Page Headers

## Define header rendering function
#macro(renderPageHeader)
  #set($doc.pageAdded)
    $drawImage("logo.png", 0, 0, 100, 40)
    $addText("Page " + $pageNumber, 12, true)
  #end
#end

## First page
$renderPageHeader()
$exporter.exportMainSheet($gridSettings, "", "")

## Multi-page table - each page needs header
#if($rowCount > 50)
  $exporter.addPage()
  $renderPageHeader()
  ## Continue with next page content
#end

Baseline Filtering

Baselines can be included, excluded, or filtered in PDF exports:

Accessing Baselines

## Check if baselines are present
#if($document.baselines && $document.baselines.size() > 0)
  ## Iterate over available baselines
  #foreach($baseline in $document.baselines)
    $baseline.name
    $baseline.revision
    $baseline.created
  #end
#end

Filtering by Document Path

## Include only baselines from specific document path
#set($includeBaselines = [])
#foreach($baseline in $document.baselines)
  #if($baseline.documentPath.contains("/MyProject/"))
    $includeBaselines.add($baseline)
  #end
#end

## Export with filtered baselines
#set($filteredGrid = $filterByBaselines($gridSettings, $includeBaselines))
$exporter.exportMainSheet($filteredGrid, "", "")

Filtering by Baseline ID

## Include specific baseline by ID
#set($targetBaseline = "baseline-v2.1")
#if($document.baselines)
  #foreach($baseline in $document.baselines)
    #if($baseline.id.equals($targetBaseline))
      ## This baseline is included
    #end
  #end
#end

Export Comparison View

When comparing two revisions, additional context is available:
## Check if in comparison mode
#if($isInCompare)
  Comparing revision $currentRevision against baseline $compareRevision
  Show unchanged items: $showUnchanged
End

## Conditionally include items based on change status
#foreach($item in $gridSettings.data)
  #if($item.hasChanged || $showUnchanged)
    ## Include in PDF
  #end
#end

Error Handling and Validation

Script Error Response

## Graceful error handling
#try
  $exporter.exportMainSheet($gridSettings, "", "")
#catch($error)
  Error: $error.message
  ## Continue with default export
  $defaultExporter.exportMainSheet($gridSettings)
#end

STOP Mechanism

## Gracefully halt export with message
#if($invalidConfiguration)
  #set($STOP)
  Error: Configuration is invalid. Please fix before exporting.
#end

## Export continues normally if condition not met

Sample Velocity Template

#set($title = $document.name)
#set($author = $document.author)
#set($revision = $document.revision)

## Document header
$addHeading($title, 1)
$addText("Revision " + $revision + " | Author: " + $author, 10, false)
$addText("Generated: " + $dateFormat, 9, false)

$exporter.addPage()

## Configure page headers for multi-page export
#set($doc.pageAdded)
  $drawImage("company-logo.png", 0, 0, 150, 40)
#end

## Export main grid
$exporter.exportMainSheet(
  $gridSettings,
  "",
  "N/A"
)

## Export rating definitions if used
#if($config.ratings && $config.ratings.size() > 0)
  $exporter.addPage()
  $addHeading("Rating Scales", 2)
  #foreach($rating in $config.ratings.values())
    $exporter.exportRatingTable($rating.id)
  #end
#end

## Export enum definitions if used
#if($config.enums && $config.enums.size() > 0)
  $exporter.addPage()
  $addHeading("Enumeration Values", 2)
  #foreach($enum in $config.enums.values())
    $exporter.exportEnumTable($enum.id)
  #end
#end

API Flow Diagram

User Clicks Export to PDF

  Fetch PDF Export Script
  from /api/pdfscript endpoint

  Execute Velocity Template
  with full context

  Populate Variables:
    - $document metadata
    - $gridSettings data
    - $exporter utilities
    - $config styling

  Build PDF:
    - Add headings/text
    - Export grid table(s)
    - Apply styling
    - Format cells by type
    - Handle multi-page breaks

  Render & Download PDF
PDF export Velocity templates are configured via risksheetPdfExport.vm property and can be attached to Polarion documents for per-document customization or stored in global templates for project-wide defaults.
For exports with hundreds of rows, configure reasonable row limits or use sub-table exports to create focused, manageable PDF sections rather than single massive tables.
Baseline filtering must be implemented in your Velocity template. Baselines are provided in context but require explicit filtering logic to include or exclude from the PDF output.
Support TicketsSource Code
  • RisksheetViewServlet.java
  • ExportToPdf.ts
  • ExportToPdfCommand.ts
  • CommandFactory.ts
  • PdfExportConfigurationService.java