Skip to main content

Prerequisites

  • Administrator permissions or document-level configuration access
  • Basic understanding of Velocity template syntax
  • Familiarity with the risksheetPdfExport.vm template file

Attach Custom Export Script

  1. Create a file named risksheetPdfExport.vm with your custom Velocity script
  2. Navigate to your Risksheet document in Polarion
  3. Click Edit Document
  4. In the document editor, click Attachments tab
  5. Upload the risksheetPdfExport.vm file as an attachment
  6. Save the document
The custom script will automatically be loaded during the next PDF export operation.

Script Execution Context

Your Velocity script has access to a rich context object with the following variables:
VariableDescription
exporterMain export utility for rendering grid data
PDFExportPDF generation library with layout controls
GridPDFGrid-specific PDF rendering utilities
docPDF document object for page management
isInCompareBoolean indicating comparison mode
compareRevisionRevision ID being compared (if applicable)
currentRevisionCurrent document revision
showUnchangedBoolean for comparison display mode
customTableGridSettingsConfiguration for table rendering
Your script automatically includes pdfExportMacros.vm, which provides utility macros for common operations like rendering tables, headers, and footers.
## Add company logo to every page
#set($logo = "path/to/company-logo.png")
$doc.pageAdded({
  $PDFExport.drawImage($logo, 20, 20, 150, 50)
  $PDFExport.text("Risk Analysis Report", 200, 35, {"fontSize": 18, "bold": true})
})

## Export main grid with default settings
$exporter.exportMainSheet()
The doc.pageAdded event handler must be called after each #newPage() statement. Page event handlers are not inherited across page breaks—you must reapply them explicitly for each new page.

Example: Multi-Page Table with Persistent Headers

## Define reusable header function
#macro(renderHeader)
  $doc.pageAdded({
    $PDFExport.drawImage("logo.png", 20, 20, 100, 40)
    $PDFExport.text("Page $doc.pageNumber", 500, 30, {"fontSize": 10})
  })
#end

## Render header on first page
#renderHeader()

## Export main table
$exporter.exportMainSheet()

## Add supplementary data on new page
#newPage()
#renderHeader()  ## Re-apply header for new page
$exporter.exportRatingTable("severity")
$exporter.exportEnumTable("risk_category")

Control Column Visibility

Hide specific columns during export by passing a comma-separated binding list:
## Export grid with formula columns hidden
$exporter.exportMainSheet("calculated_rpn,auto_description,internal_notes")
Columns are automatically restored after export completes.

Export Workflow Diagram

diagram
Enum fields may not render with the same formatting in PDF exports as they appear in the interactive interface. Consider using custom rendering logic in your script to improve enum display.

Common Pitfalls

Velocity syntax errors in your custom script may cause the PDF export to fail without clear error messages. Test your script incrementally and verify PDF generation after each change.
If your script needs to abort PDF generation, throw a STOP error:
#if($someCondition)
  #set($error = "STOP: Export cancelled due to missing data")
  $error
#end

Verification

  1. Click Export to PDF in your Risksheet
  2. Wait for PDF generation to complete
  3. Open the downloaded PDF file
You should now see your custom headers, layout, and styling applied throughout the document. Images and text defined in doc.pageAdded events should appear on every page.

See Also

Support TicketsSource Code
  • ExportToPdf.ts
  • RisksheetViewServlet.java
  • PdfExportConfigurationService.java
  • ExportToPdfCommand.ts
  • CommandFactory.ts