Skip to main content

Template Location and Configuration

PropertyValueDescription
Template FilenamerisksheetPdfExport.vmStandard name for PDF export Velocity template in RISKSHEET documents
Template StorageDocument AttachmentStored as attachment in Polarion wiki documents
Configuration PropertyrisksheetPdfExport.vmProperty in AppConfig that references the template file name
Template LoadingPdfExportConfigurationServiceService that loads template from document attachments with template inheritance
Cache BehaviorRevision-based invalidationTemplate cached by revision; changes invalidate cache automatically
If a template is not found on the document, the system searches the document’s template hierarchy automatically. This allows global templates to be inherited by all documents in a project.

Core Template Structure

A minimal PDF export template follows this structure:
#* PDF Export Template for RISKSHEET *#
#set( $pdfExport = $pdfExportMacros )

#* Initialize page settings *#
$pdfExport.setPageSize("A4")
$pdfExport.setPageOrientation("landscape")

#* Optional: Add header on first page *#
#set( $doc.pageAdded = true )
$pdfExport.drawImage("/path/to/header.png", 0, 0, 595, 50)

#* Add main content *#
#foreach( $item in $items )
  $pdfExport.addRow($item)
#end

Available Context Variables

Document Context

VariableTypeDescription
$docDocumentCurrent Polarion document being exported
$doc.projectIdStringProject identifier for the document
$doc.titleStringDocument title/name
$doc.moduleIdStringModule identifier if document is a module
$doc.pageAddedBooleanFlag indicating page has been initialized; must be reapplied after #newPage()

Export Data

VariableTypeDescription
$itemsListArray of work items to be exported
$columnsListColumn definitions for the grid
$configAppConfigComplete RISKSHEET configuration object
$gridSettingsGridSettingsExport-specific grid settings
$isInCompareBooleanWhether exporting comparison view
$compareRevisionStringRevision being compared (if in comparison mode)
$currentRevisionStringCurrent/head revision identifier
$showUnchangedBooleanWhether to show unchanged items in comparison

Transaction and Services

VariableTypeDescription
$transactionTransactionPolarion transaction context for database access
$trackerTrackerServiceTracker service for work item queries
$securitySecurityServiceSecurity service for permission checks
$repositoryRepositoryServiceRepository service for file/attachment access

PDF Export Macros (pdfExportMacros.vm)

The $pdfExportMacros object provides helper functions for PDF generation:

Page Management

#* Set page dimensions and orientation *#
$pdfExport.setPageSize("A4")           #* Size: A4, Letter, Legal, etc. *#
$pdfExport.setPageOrientation("landscape")  #* landscape or portrait *#
$pdfExport.setPageMargins(26, 26, 26, 26)   #* top, right, bottom, left in points *#

#* Create new page (must reapply doc.pageAdded content after) *#
$pdfExport.newPage()

Content Rendering

#* Draw image on page *#
$pdfExport.drawImage("/path/to/image.png", x, y, width, height)

#* Add table from grid items *#
$pdfExport.addTable($items, $columns)

#* Add rating scale table *#
$pdfExport.exportRatingTable("severity")

#* Add enum definition table *#
$pdfExport.exportEnumTable("riskType")

#* Add sub-table (nested items) *#
$pdfExport.exportSubTable($items, "mitigation", $columns)

#* Add downstream traceability table *#
$pdfExport.exportDownstreamTable($items, "relatedTasks", $columns)

Text and Formatting

#* Add formatted text *#
$pdfExport.addText("Title Text", "heading1")
$pdfExport.addText("Body paragraph", "normal")

#* Add paragraph with spacing *#
$pdfExport.addParagraph("Content", 12, true)  #* text, pointSize, bold *#

#* Add horizontal line/divider *#
$pdfExport.addLine(1.0, "#000000")

Multi-Page Image Headers

Images added via doc.pageAdded must be reapplied after each page break. The event handler is not automatically inherited:
#* Initial page header *#
#set( $doc.pageAdded = true )
$pdfExport.drawImage("/header.png", 0, 0, 595, 40)

#* Table that may span multiple pages *#
$pdfExport.addTable($items, $columns)

#* After page break, reapply header *#
$pdfExport.newPage()
#set( $doc.pageAdded = true )
$pdfExport.drawImage("/header.png", 0, 0, 595, 40)

#* Continue with page content *#
$pdfExport.addText("Page 2 Content", "normal")
The doc.pageAdded handler controls page initialization events. It is not automatically carried forward after #newPage() calls. You must explicitly set #set( $doc.pageAdded = true ) after each page break if you want headers or initialization code to execute on subsequent pages.

Baseline Filtering

For documents with multiple baselines, control which baseline data appears in the PDF export:
#* Filter items by baseline/document path *#
#set( $filteredItems = [] )
#foreach( $item in $items )
  #if( $item.documentId.equals("target-doc-id") )
    #set( $result = $filteredItems.add($item) )
  #end
#end

$pdfExport.addTable($filteredItems, $columns)
Alternatively, filter by document path pattern:
#set( $filteredItems = [] )
#foreach( $item in $items )
  #if( $item.documentPath.contains("/release-v2.0/") )
    #set( $result = $filteredItems.add($item) )
  #end
#end

$pdfExport.addTable($filteredItems, $columns)
Use CaseFilter ApproachExample
Single baselineNo filteringExport all items in document
Multi-baseline by IDDocument ID matching$item.documentId.equals("my-doc-id")
Multi-baseline by pathPath pattern matching$item.documentPath.contains("/release-v1.0/")
Regulated exportsDocument version filteringFilter by baseline version for compliance

Cell Type Formatting in Export

Different column types are automatically formatted for PDF:
Column TypePDF RenderingExample Output
Boolean (Checkbox)Text representationtrue or false
Item LinkPlain text ID and titleREQ-001: System shall log errors
Multi-Item LinkNewline-separated listREQ-001\nREQ-002\nREQ-003
Multi-EnumEnum labels from configHigh, Critical
Server-RenderHTML stripped, </li> to newlineClean text with list formatting
DateFormatted per column.format2024-02-12 or locale-specific

Style Preservation

CSS styling from the web interface is automatically transferred to PDF cells:
#* Styles from .inner-cell and .wj-cell classes are preserved *#
#* Background colors, text colors, and alignment carry forward *#
$pdfExport.addTable($items, $columns)

Empty Cell Placeholder

Configure placeholder text for null or empty cells:
#* Set before adding table *#
$pdfExport.setEmptyPlaceholder("—")  #* Use em-dash for empty cells *#
$pdfExport.addTable($items, $columns)

Custom Script Execution

PDF export supports custom JavaScript for advanced logic:
#* Server-side JavaScript can be injected *#
#set( $script = "/api/pdfscript?revision=$currentRevision" )
#* Script receives: exporter, PDFExport, GridPDF, customTableGridSettings, isInCompare, compareRevision, currentRevision, showUnchanged, doc *#
If a custom script encounters an error, it can throw a STOP exception to gracefully terminate export and display an error message to the user.

Example: Complete PDF Export Template

#set( $pdfExport = $pdfExportMacros )
$pdfExport.setPageSize("A4")
$pdfExport.setPageOrientation("landscape")
$pdfExport.setPageMargins(26, 26, 26, 26)

#* Add document header on first page *#
#set( $doc.pageAdded = true )
$pdfExport.drawImage("/company-logo.png", 0, 0, 595, 35)
$pdfExport.addText("$doc.title - Risk Assessment", "heading1")
$pdfExport.addText("Project: $doc.projectId | Generated: #date('yyyy-MM-dd')", "normal")
$pdfExport.addLine(1.0, "#cccccc")

#* Filter to current baseline if multi-baseline document *#
#set( $filteredItems = [] )
#foreach( $item in $items )
  #if( $item.documentId.equals("$doc.moduleId") )
    #set( $result = $filteredItems.add($item) )
  #end
#end

#* Export main grid *#
$pdfExport.addTable($filteredItems, $columns)

#* Add ratings reference on new page *#
$pdfExport.newPage()
#set( $doc.pageAdded = true )
$pdfExport.drawImage("/company-logo.png", 0, 0, 595, 35)
$pdfExport.addText("Risk Rating Scales", "heading1")
$pdfExport.exportRatingTable("severity")

Troubleshooting

Images not appearing on subsequent pages

Problem: Header images appear on first page but not after page breaks. Solution: Always set #set( $doc.pageAdded = true ) immediately after $pdfExport.newPage() calls before drawing images.

Baseline data missing from export

Problem: Expected baseline items don’t appear in PDF output. Solution: Check document filter logic. Use $item.documentId or $item.documentPath to filter items by baseline or document version before passing to addTable().

Cell formatting lost in PDF

Problem: Styles from web interface don’t appear in PDF. Solution: Verify that column CSS classes (.inner-cell and .wj-cell) are properly defined in configuration. PDF export reads these styles automatically.
Support TicketsSource Code
  • PdfExportConfigurationService.java
  • RisksheetViewServlet.java
  • ExportToPdf.ts
  • CommandFactory.ts
  • ExportToPdfCommand.ts