Template Location and Configuration
Property Value Description Template Filename risksheetPdfExport.vmStandard name for PDF export Velocity template in RISKSHEET documents Template Storage Document Attachment Stored as attachment in Polarion wiki documents Configuration Property risksheetPdfExport.vmProperty in AppConfig that references the template file name Template Loading PdfExportConfigurationService Service that loads template from document attachments with template inheritance Cache Behavior Revision-based invalidation Template 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
Variable Type Description $docDocument Current Polarion document being exported $doc.projectIdString Project identifier for the document $doc.titleString Document title/name $doc.moduleIdString Module identifier if document is a module $doc.pageAddedBoolean Flag indicating page has been initialized; must be reapplied after #newPage()
Export Data
Variable Type Description $itemsList Array of work items to be exported $columnsList Column definitions for the grid $configAppConfig Complete RISKSHEET configuration object $gridSettingsGridSettings Export-specific grid settings $isInCompareBoolean Whether exporting comparison view $compareRevisionString Revision being compared (if in comparison mode) $currentRevisionString Current/head revision identifier $showUnchangedBoolean Whether to show unchanged items in comparison
Transaction and Services
Variable Type Description $transactionTransaction Polarion transaction context for database access $trackerTrackerService Tracker service for work item queries $securitySecurityService Security service for permission checks $repositoryRepositoryService Repository 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")
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 Case Filter Approach Example Single baseline No filtering Export all items in document Multi-baseline by ID Document ID matching $item.documentId.equals("my-doc-id")Multi-baseline by path Path pattern matching $item.documentPath.contains("/release-v1.0/")Regulated exports Document version filtering Filter by baseline version for compliance
Different column types are automatically formatted for PDF:
Column Type PDF Rendering Example Output Boolean (Checkbox) Text representation true or falseItem Link Plain text ID and title REQ-001: System shall log errorsMulti-Item Link Newline-separated list REQ-001\nREQ-002\nREQ-003Multi-Enum Enum labels from config High, CriticalServer-Render HTML stripped, </li> to newline Clean text with list formatting Date Formatted per column.format 2024-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().
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 Tickets Source Code
PdfExportConfigurationService.java
RisksheetViewServlet.java
ExportToPdf.ts
CommandFactory.ts
ExportToPdfCommand.ts