Revision as of 09:56, 25 April 2025 by Redaktion (talk | contribs)
Review PDF export compatibility!The PDF export script for BlueSpice 4 is different.


PDF Export from CLI

You can export PDF files from your MediaWiki installation via the command line by using a specification file in JSON format.

Create a JSON specification file

This file defines all the parameters for the export process. Below is a minimal example:

{
   "module": "batch",
   "params": {
     "filename": "MyExport.pdf",
     "filesystem-path": "/app/d/pdfcreator/cache",
     "target": "filesystem",
     "user": "WikiSysop"
   },
   "options": {
     "attachments": true
   },
   "pages": [
     {
       "type": "page",
       "target": "Main_Page"
     }
   ]
 }

You can expand this file to include more pages, templates, or custom options. Here’s a more advanced example:

{
   "module": "batch",
   "params": {
     "filename": "FullExport.pdf",
     "filesystem-path": "/var/pdf_exports",
     "target": "filesystem",
     "user": "ExportAdmin",
     "title": "My Export Title",
     "template": "AdvancedTemplate",
     "logo": "<nowiki>https://example.com/logo.png</nowiki>",
     "export-date": "2025-04-25",
     "export-time": "14:00"
   },
   "options": {
     "attachments": true,
     "suppress-links": false,
     "embed-page-toc": true,
     "no-redirect": true
   },
   "pages": [
     {
       "type": "page",
       "target": "Main_Page",
       "label": "Hauptseite"
     },
     {
       "type": "pageWithSubpages",
       "target": "Category:Documentation",
       "label": "Dokumentation"
     },
     {
       "type": "pageWithLinkedPages",
       "target": "Help:Editing",
       "label": "Bearbeitungshilfe"
     }
   ]
 }

Start export from CLI

Once your JSON file is ready, run the following command to start the export:

php extensions/PDFCreator/maintenance/CreatePDF.php cache/specification.json

Available parameters

General parameters (params):

  • filename: Name of the exported PDF.
  • filesystem-path: Path to store the exported file.
  • target: Can be filesystem or download.
  • user: Username used for export context.
  • title: Optional title for the PDF.
  • template: Optional PDF template.
  • logo: Optional logo URL.
  • export-date, export-time: Timestamp data for PDF metadata.

Options (options):

  • attachments: true to include media files.
  • suppress-links: true to disable links in the PDF.
  • embed-page-toc: true to include a table of contents.
  • no-redirect: true to avoid following redirects.

Page definitions (pages):

  • type: One of page, pageWithSubpages, pageWithLinkedPages.
  • target: Page name.
  • label: Custom label (optional).
  • params: Page-specific options (e.g., rev-id, status).

Automating with CronJob

To automate regular exports, set up a CronJob:

php {MW_ROOT}/extensions/PDFCreator/maintenance/CreatePDF.php --specification-file={MW_ROOT}/extensions/BlueSpiceFoundation/data/spec.json

Replace {MW_ROOT} with your MediaWiki installation path.

Migration from older format

If you're using the legacy pdf or bookpdf module format, migrate to the new batch format using the following mapping:

Old format

{
   "module": "pdf",
   "attachments": 1,
   "recursive": 1,
   "title": "MyPDF",
   "target": "localfilesystem",
   "target-file-name": "All.pdf",
   "target-file-path": "/path/to/target-file"
 }

New format

{
   "module": "batch",
   "params": {
     "filename": "All.pdf",
     "filesystem-path": "/path/to/target-file",
     "target": "filesystem",
     "title": "MyPDF"
   },
   "options": {
     "attachments": true
   },
   "pages": [
     {
       "type": "page",
       "target": "Main_Page"
     }
   ]
 }

Key changes

Old Parameter New Parameter Notes
module=pdf module=batch Unified module name
attachments options.attachments Moved into options, uses true/false
recursive Removed Use pageWithLinkedPages instead
title params.title Moved into params
target=localfilesystem params.target=filesystem Updated value
target-file-name params.filename Renamed and moved into params
target-file-path params.filesystem-path Renamed and moved into params



To submit feedback about this documentation, visit our community forum.