xWiki PDF Export: Professional Documents from Wiki Content

Wiki content is meant to be collaborative and fluid, but there are moments when you need a fixed, polished artifact. Board reports, compliance documentation, client deliverables, and printed reference manuals all demand a format that travels well beyond the browser. xWiki's PDF export capabilities bridge this gap, transforming wiki pages into professionally formatted documents complete with headers, footers, tables of contents, and consistent typography.

Built-In PDF Export

Every xWiki page offers a PDF export option through the Export menu. The built-in renderer converts the page's XHTML content into a PDF document using the Apache FOP (Formatting Objects Processor) engine or, in newer installations, a CSS-based rendering pipeline. The result is a single-page PDF that preserves text formatting, tables, and inline images. For straightforward documentation pages, this works without any configuration. But the default output is utilitarian, not polished, which is why most organizations invest time in customizing the PDF templates.

Customizing PDF Templates with CSS

xWiki's PDF export pipeline accepts custom CSS that controls the printed output independently of the screen stylesheet. This means you can define page margins, font sizes, header and footer content, and page break behavior without affecting how the page appears in the browser. The PDF template is a wiki page itself, typically located at XWiki.PDFTemplate, containing CSS rules within an @media print context or applied directly to the FOP rendering chain.

Common customizations include setting corporate fonts, adjusting margins to accommodate letterhead, and defining styles for code blocks that render well on paper. A typical PDF stylesheet override might look like this:

@page {
  size: A4;
  margin: 25mm 20mm 30mm 20mm;

  @top-center {
    content: "CONFIDENTIAL - Internal Use Only";
    font-size: 8pt;
    color: #999999;
  }

  @bottom-left {
    content: "Acme Corp Knowledge Base";
    font-size: 8pt;
  }

  @bottom-right {
    content: "Page " counter(page) " of " counter(pages);
    font-size: 8pt;
  }
}

body {
  font-family: 'Noto Sans', sans-serif;
  font-size: 11pt;
  line-height: 1.5;
}

pre, code {
  font-family: 'Noto Sans Mono', monospace;
  font-size: 9pt;
  background-color: #f5f5f5;
  padding: 2mm;
  border: 0.5pt solid #dddddd;
}

h1 { page-break-before: always; }
table { page-break-inside: avoid; }

These rules give you precise control over the printed output. The page-break-before and page-break-inside properties are particularly important for producing documents where chapters start on new pages and tables are not awkwardly split across page boundaries.

Headers, Footers, and Table of Contents

PDF headers and footers are configured through the @page CSS rules shown above or through Velocity template logic that injects content into the PDF rendering context. You can include static text like document classification labels, dynamic content like the export date, or even small images such as a company logo. The page counter variables counter(page) and counter(pages) provide automatic pagination.

Table of contents generation is handled by xWiki's export engine, which scans the heading hierarchy of the exported content and produces a linked TOC at the beginning of the document. For multi-page exports, this TOC spans all included pages, giving readers a navigable overview of the entire document. Heading levels map to TOC indentation, so maintaining a consistent heading structure in your wiki content directly improves the quality of exported documents.

Batch Export of Multiple Pages

Exporting a single page is straightforward, but real-world document generation often requires combining multiple wiki pages into a single PDF. xWiki supports batch export through the Export Application, which lets you select a set of pages or an entire space for combined export. The pages are concatenated in the order you specify, with the table of contents reflecting the full document structure.

This capability is essential for producing manuals, onboarding guides, or compliance document packages. A space structured as chapters, such as a product documentation tree, can be exported as a complete book with a single action. For organizations managing structured data applications, batch export can include LiveTable data rendered as formatted tables within the PDF.

Handling Images and Diagrams

Images embedded in wiki pages are included in PDF exports automatically, but resolution and sizing deserve attention. Images displayed at browser-appropriate resolutions may appear blurry in print. Provide source images at 150 DPI or higher for any content likely to be exported. SVG diagrams render crisply at any size and are the preferred format for architecture diagrams, flowcharts, and technical illustrations.

Diagrams created with xWiki's built-in diagramming tools or the draw.io integration export as embedded images within the PDF. If diagram fidelity is critical, consider exporting diagrams separately at high resolution and attaching them to the wiki page as dedicated image files rather than relying on the embedded rendering.

LaTeX Integration for Technical Documents

For scientific and engineering teams, xWiki supports LaTeX rendering through the LaTeX macro. Mathematical formulas, equations, and technical notation can be authored in LaTeX syntax within wiki pages and rendered correctly in both the browser view and PDF exports. This eliminates the need to maintain separate LaTeX documents alongside wiki content for formula-heavy material.

The LaTeX rendering pipeline converts notation into images or MathML for browser display and into native PDF constructs during export. Teams producing research papers, technical specifications, or academic documentation can maintain a single source of truth in xWiki while generating publication-quality PDFs when needed.

Automated Report Generation

Beyond manual exports, xWiki's scripting capabilities enable automated PDF generation on a schedule. A Groovy or Velocity script can programmatically invoke the PDF export API, selecting pages based on metadata, modification dates, or structured data queries. The resulting PDF can be attached to a wiki page, emailed to a distribution list, or stored in an external document management system.

This pattern is valuable for recurring reports: weekly status summaries, monthly compliance snapshots, or quarterly review packages. The wiki content is maintained collaboratively throughout the reporting period, and the automated export captures a point-in-time snapshot without manual intervention. Combined with xWiki's theming capabilities, these automated reports can carry full corporate branding.

Professional PDF output turns your xWiki instance from a collaboration tool into a publishing platform. Whether you need branded client deliverables, compliance documentation, or technical manuals, MassiveGRID's managed xWiki hosting provides the processing power and memory to handle large batch exports without impacting wiki performance. Talk to our team about configuring your xWiki environment for document generation at scale.

MassiveGRID hosts xWiki on high-performance cloud infrastructure with generous CPU and memory allocations, ensuring that PDF exports and batch document generation complete quickly even for large content libraries.