Setup:Installation Guide/Advanced/Maintenance scripts/CreatePDF: Difference between revisions

Redaktion (talk | contribs)
No edit summary
Redaktion (talk | contribs)
No edit summary
Tag: 2017 source edit
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Textbox|boxtype=warning|header=Review PDF export compatibility!|text=The [[en4:Setup:Installation_Guide/Advanced/Maintenance_scripts/export|PDF export script for BlueSpice 4]] is different.|icon=yes}}
{{Textbox|boxtype=warning|header=Review PDF export compatibility!|text=The [[en4:Setup:Installation_Guide/Advanced/Maintenance_scripts/export|PDF export script for BlueSpice 4]] is different. If you want to migrate your BlueSpice 4 script to BlueSpice 5, [[#Migration_from_older_format|consult the migration info]].|icon=yes}}


== Export PDF from cli ==
After creating a specificaton json file, the pdf export can be triggered from CLI.


Example json content:
=== 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.
    "module": "batch",
 
    "params": {
==== Create a JSON specification file ====
        "filename": "MyExport.pdf",
This file defines all the parameters for the export process. Below is a minimal example:
        "filesystem-path": "/app/d/pdfcreator/cache",
<syntaxhighlight lang="json">{
        "target": "filesystem",
  "module": "batch",
        "user": "WikiSysop"
  "params": {
    "filename": "MyExport.pdf",
    "filesystem-path": "/app/d/pdfcreator/cache",
    "target": "filesystem",
    "user": "WikiSysop"
  },
  "options": {
    "attachments": true
  },
  "pages": [
    {
      "type": "page",
      "target": "Main_Page"
    }
  ]
}</syntaxhighlight>
You can expand this file to include more pages, templates, or custom options. Here’s a more advanced example:
<syntaxhighlight lang="json">{
  "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"
     },
     },
     "options": {
     {
        "attachments" : true
      "type": "pageWithSubpages",
      "target": "Category:Documentation",
      "label": "Dokumentation"
     },
     },
     "pages": [
     {
        {
      "type": "pageWithLinkedPages",
            "type": "page",
      "target": "Help:Editing",
            "target": "Main_Page"
      "label": "Bearbeitungshilfe"
        }
    }
    ]
  ]
  }
  }</syntaxhighlight>
Start export form CLI:<syntaxhighlight lang="php">
 
php extensions/PDFCreator/maintenance/CreatePDF.php cache/specification.json
==== Start export from CLI ====
</syntaxhighlight>
Once your JSON file is ready, run the following command to start the export:
__FORCETOC__
<code>php extensions/PDFCreator/maintenance/CreatePDF.php cache/specification.json</code>
 
=== Available parameters ===
 
==== General parameters (<code>params</code>): ====
 
* <code>filename</code>: Name of the exported PDF.
* <code>filesystem-path</code>: Path to store the exported file.
* <code>target</code>: Can be <code>filesystem</code> or <code>download</code>.
* <code>user</code>: Username used for export context.
* <code>title</code>: Optional title for the PDF.
* <code>template</code>: Optional PDF template.
* <code>logo</code>: Optional logo URL.
* <code>export-date</code>, <code>export-time</code>: Timestamp data for PDF metadata.
 
==== Options (<code>options</code>): ====
 
* <code>attachments</code>: <code>true</code> to include media files.
* <code>suppress-links</code>: <code>true</code> to disable links in the PDF.
* <code>embed-page-toc</code>: <code>true</code> to include a table of contents.
* <code>no-redirect</code>: <code>true</code> to avoid following redirects.
 
==== Page definitions (<code>pages</code>): ====
 
* <code>type</code>: One of <code>page</code>, <code>pageWithSubpages</code>, <code>pageWithLinkedPages</code>.
* <code>target</code>: Page name.
* <code>label</code>: Custom label (optional).
* <code>params</code>: Page-specific options (e.g., <code>rev-id</code>, <code>status</code>).
 
=== Automating with CronJob ===
To automate regular exports, set up a CronJob:
<code>php {MW_ROOT}/extensions/PDFCreator/maintenance/CreatePDF.php --specification-file={MW_ROOT}/extensions/BlueSpiceFoundation/data/spec.json</code>
Replace <code>{MW_ROOT}</code> with your MediaWiki installation path.
 
=== Migration from older format ===
If you're using the legacy <code>pdf</code> or <code>bookpdf</code> module format, migrate to the new <code>batch</code> format using the following mapping:
 
==== Old format ====
<syntaxhighlight lang="json">{
  "module": "pdf",
  "attachments": 1,
  "recursive": 1,
  "title": "MyPDF",
  "target": "localfilesystem",
  "target-file-name": "All.pdf",
  "target-file-path": "/path/to/target-file"
}</syntaxhighlight>
 
==== New format ====
<syntaxhighlight lang="json">{
  "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"
    }
  ]
}</syntaxhighlight>
 
==== Key changes ====
{| class="wikitable"
!Old Parameter
!New Parameter
!Notes
|-
|<code>module=pdf</code>
|<code>module=batch</code>
|Unified module name
|-
|<code>attachments</code>
|<code>options.attachments</code>
|Moved into <code>options</code>, uses <code>true/false</code>
|-
|<code>recursive</code>
|Removed
|Use <code>pageWithLinkedPages</code> instead
|-
|<code>title</code>
|<code>params.title</code>
|Moved into <code>params</code>
|-
|<code>target=localfilesystem</code>
|<code>params.target=filesystem</code>
|Updated value
|-
|<code>target-file-name</code>
|<code>params.filename</code>
|Renamed and moved into <code>params</code>
|-
|<code>target-file-path</code>
|<code>params.filesystem-path</code>
|Renamed and moved into <code>params</code>
|}

Latest revision as of 09:57, 25 April 2025

Review PDF export compatibility!The PDF export script for BlueSpice 4 is different. If you want to migrate your BlueSpice 4 script to BlueSpice 5, consult the migration info.


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.