Skip to content

Export System

SPEAR provides comprehensive export capabilities for security assessment reports. This guide covers the implemented PDF export system, public portal sharing, and planned DOCX export feature.

FormatDescriptionStatus
PDFProfessional formatted documentsImplemented
Public PortalWeb-based sharingImplemented
DOCXEditable Word documentsPlanned

5:30
PDF Export System Overview Understanding the export architecture, configuring options, and generating professional PDFs 💡 Explainer Video

The PDF export system generates professional PDFs from report content using Go Rod (headless Chrome). It integrates report sections, themes, and branding into cohesive PDF documents.

🎨 Export Architecture Diagram Illustration
flowchart LR
    A[Export Dialog] --> B[Backend Processing]
    B --> C[Fetch Report Data]
    B --> D[Fetch Theme Settings]
    B --> E[Fetch Branding]

    C --> F[Section Assembler]
    D --> F
    E --> F

    F --> G[Generate HTML]
    G --> H[Apply Theme CSS]
    H --> I[Headless Browser]
    I --> J[PDF File]
    J --> K[Download]
    K --> A
  1. Frontend UI - User configures export options in PDFExportDialog
  2. Backend API - Receives export request with configuration
  3. Data Assembly - Fetches report, sections, findings, and metadata
  4. Theme Application - Applies selected theme styles and branding
  5. HTML Generation - Builds complete HTML document with cover page, TOC, sections
  6. Image Processing - Converts images to base64 for embedding
  7. PDF Rendering - Go Rod (headless Chrome) converts HTML to PDF
  8. File Storage - PDF stored temporarily for download
  9. Download - Returns URL for client download
🖥️ PDFExportDialog with All Options Screenshot
4:15
Configuring PDF Export Options Selecting themes, adjusting page settings, configuring headers/footers, and using async mode 🎥 Demo Video
OptionTypeDefaultDescription
themeIdstring-Theme to apply for styling
includeCoversbooleantrueInclude cover pages
includeTocbooleantrueGenerate table of contents
pageSizestring'A4'Page size (A4, Letter, Legal, A3, A5)
orientationstring'portrait'Portrait or landscape
marginsobject{top: 1.0, right: 1.0, bottom: 1.0, left: 1.0}Page margins in inches
includeHeaderbooleantrueInclude page headers
includeFooterbooleantrueInclude page footers
darkModebooleanfalseUse dark mode styling
asyncbooleanfalseUse async processing for large reports
SizeDimensionsCommon Use
A48.27 x 11.69 inInternational standard
Letter8.5 x 11 inUS standard
Legal8.5 x 14 inLegal documents
A311.69 x 16.54 inLarge format
A55.83 x 8.27 inCompact documents

🖥️ Theme Configuration Interface Screenshot
7:00
Creating and Applying Custom Themes Configuring colors, fonts, table styles, and custom CSS for branded PDF exports 📚 Video Tutorial

Themes control the visual appearance of exported PDFs.

PropertyDescription
BackgroundPage background color
TextPrimary text color
PrimaryAccent/highlight color
HeadingHeading text color (H1-H4)
MutedSecondary text color
PropertyDescription
Body FontMain content font family
Heading FontHeading font family
Code FontMonospace font for code
Base SizeBase font size in points
PropertyDescription
BordersBorder style and color
Header BackgroundTable header background color
Cell PaddingInternal cell padding
Alternating RowsZebra striping for rows

Themes support custom CSS injection for advanced styling:

/* Custom theme CSS */
.severity-critical {
background-color: #dc2626;
color: white;
}
.finding-card {
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

🖥️ Branding Integration Settings Screenshot

Organization branding is automatically applied to exported documents.

PropertyDescription
Light Mode LogoLogo for light backgrounds
Dark Mode LogoLogo for dark backgrounds
Logo PositionHeader placement (left, center, right)
Logo SizeMaximum dimensions
PropertyDescription
Primary ColorMain brand color
Accent ColorSecondary brand color

Customizable footer text with placeholders:

  • {{page}} - Current page number
  • {{pages}} - Total page count
  • {{date}} - Export date
  • {{report.title}} - Report title

Logos are served from PocketBase storage:

/api/files/branding_settings/{recordId}/{filename}

  1. Fetch section definitions from report template
  2. Build hierarchical section tree
  3. Process each section by type
  4. Generate HTML fragments
  5. Combine with page break rules
TypeProcessing
staticRender fixed template content
freeformRender user-edited rich text
dynamicGenerate from data (findings, assets)
pdf_onlyInclude only in PDF exports

Sections marked as repeating generate content for each service:

[Service A Section]
- Service A Content
- Service A Findings
[Service B Section]
- Service B Content
- Service B Findings

Page breaks inserted based on heading levels:

HeadingPage Break
H1Always before
H2Configurable
H3+Never

Findings are rendered with severity badges, CVSS scores, and structured content:

<div class="finding">
<div class="finding-header">
<span class="severity severity-high">High</span>
<h3>SQL Injection in Login Form</h3>
<span class="cvss">CVSS: 8.6</span>
</div>
<div class="finding-body">
<!-- Description, remediation, etc. -->
</div>
</div>

For large reports (50+ sections), async processing avoids timeouts.

  1. Export request creates a queue entry for processing
  2. Background worker processes the export
  3. Progress updates available while processing
  4. Download available when complete
StateDescription
queuedWaiting for processing
processingExport in progress
completedExport finished successfully
failedExport failed with error
{
"queueId": "job-xyz789",
"status": "processing",
"progress": 65,
"message": "Processing section 13 of 20"
}
ModeTimeout
Synchronous5 minutes
Asynchronous30 minutes

🖥️ Export History Interface Screenshot

Track previous exports for auditing and re-download.

FieldDescription
Export DateWhen export was generated
FormatPDF or Portal
UserWho initiated export
OptionsConfiguration used
FileStored export file URL
Statuscompleted, failed, or expired

Previous exports are re-downloadable until cleanup:

  1. Navigate to Export History in the report editor
  2. Select previous export
  3. Click Download

🖥️ Public Portal Configuration Screenshot

Web-based report sharing for client review.

  • Custom branding application
  • Interactive navigation
  • Access control with tokens
  • Expiration settings
  • View tracking
SettingDescription
TokenSecure access token (auto-generated)
ExpiryAccess expiration date
StatusActive, expired, or revoked
Access CountNumber of times portal has been viewed

Public portals are accessed via a unique token-based URL provided when creating the portal share.


  • Preserves rich text formatting
  • Tables with styling
  • Images embedded
  • Editable in Microsoft Word

Similar to PDF export with format-specific adjustments:

  • No page break configuration (Word handles pagination)
  • Font embedding options
  • Compatibility mode selection

POST /api/reports/{id}/export-docx


Daily cleanup job removes old exports:

  • Default retention: 7 days
  • Configurable via PDF_RETENTION_DAYS environment variable

Administrators can manually delete exports from the export history interface.


  • Compress images before upload
  • Use appropriate dimensions (not larger than needed)
  • Prefer JPEG for photos, PNG for diagrams

For reports with:

  • 50+ sections
  • Many images
  • Complex findings tables

Themes are cached per export. Avoid inline styles in content that override theme settings.

  • Keep finding descriptions concise
  • Use summaries for very long technical details
  • Link to external references when appropriate

Causes:

  • Empty section content
  • Theme template errors
  • CSS rendering issues

Solutions:

  1. Verify section content exists
  2. Check theme template syntax
  3. Test with default theme

Causes:

  • Invalid image URLs
  • Images too large
  • PocketBase file access issues

Solutions:

  1. Verify image URLs are accessible
  2. Check file size limits
  3. Re-upload images

Causes:

  • Large report (50+ sections)
  • Many high-resolution images
  • Server resource constraints

Solutions:

  1. Use async mode
  2. Optimize images
  3. Split into multiple reports

Causes:

  • Theme template missing header/footer sections
  • Options disabled in export request

Solutions:

  1. Verify theme includes header/footer templates
  2. Check includeHeader and includeFooter options

Causes:

  • Custom fonts not available
  • Font embedding disabled

Solutions:

  1. Use web-safe fonts
  2. Enable font embedding in theme
  3. Test PDF in different viewers