Your Velocity script has access to a rich context object with the following variables:
Variable
Description
exporter
Main export utility for rendering grid data
PDFExport
PDF generation library with layout controls
GridPDF
Grid-specific PDF rendering utilities
doc
PDF document object for page management
isInCompare
Boolean indicating comparison mode
compareRevision
Revision ID being compared (if applicable)
currentRevision
Current document revision
showUnchanged
Boolean for comparison display mode
customTableGridSettings
Configuration 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.
## 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")
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.
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:
Copy
Ask AI
#if($someCondition) #set($error = "STOP: Export cancelled due to missing data") $error#end
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.