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

Redaktion (talk | contribs)
Created page with "== Running the script == The script to export wiki pages to PDF is executed from: <syntaxhighlight lang="text"> php {MW_ROOT}/extensions/BlueSpiceUniversalExport/maintenance/e..."
 
Redaktion (talk | contribs)
No edit summary
Tag: 2017 source edit
 
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Running the script ==
{{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}}
The script to export wiki pages to PDF is executed from: <syntaxhighlight lang="text">
 
php {MW_ROOT}/extensions/BlueSpiceUniversalExport/maintenance/export.php --specification-file=spec.json
 
</syntaxhighlight>The specification file spec.json can have the following content:<syntaxhighlight lang="text">
=== 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": "pdf",
 
    "attachments": 1,
==== Create a JSON specification file ====
    "recursive": 1,
This file defines all the parameters for the export process. Below is a minimal example:
    "title": "PDF",
<syntaxhighlight lang="json">{
    "target": "localfilesystem",
  "module": "batch",
    "target-file-name": "All.pdf",
  "params": {
    "target-file-path": "/path/to/target-file"
    "filename": "MyExport.pdf",
}
    "filesystem-path": "/app/d/pdfcreator/cache",
</syntaxhighlight>
    "target": "filesystem",
{| class="wikitable" style="width: 100%;"
    "user": "WikiSysop"
|+
  },
! style="width:200px;" |Key
  "options": {
! style="width:200px;" |Value
    "attachments": true
!Description
  },
|-
  "pages": [
| style="width:200px;" |module
    {
| style="width:200px;" |pdf
      "type": "page",
|
      "target": "Main_Page"
|-
    }
| style="width:200px;" |attachments
  ]
| style="width:200px;" |1
}</syntaxhighlight>
0
You can expand this file to include more pages, templates, or custom options. Here’s a more advanced example:
|
<syntaxhighlight lang="json">{
|-
  "module": "batch",
| style="width:200px;" |recursive
  "params": {
| style="width:200px;" |1
    "filename": "FullExport.pdf",
0
    "filesystem-path": "/var/pdf_exports",
|
    "target": "filesystem",
|-
    "user": "ExportAdmin",
| style="width:200px;" |title
    "title": "My Export Title",
| style="width:200px;" |string
    "template": "AdvancedTemplate",
|
    "logo": "<nowiki>https://example.com/logo.png</nowiki>",
|-
    "export-date": "2025-04-25",
| style="width:200px;" |target
    "export-time": "14:00"
| style="width:200px;" |localfilesystem
  },
|
  "options": {
|-
    "attachments": true,
| style="width:200px;" |target-file-name
    "suppress-links": false,
| style="width:200px;" |
    "embed-page-toc": true,
|
    "no-redirect": true
|-
  },
| style="width:200px;" |target-file-path
  "pages": [
| style="width:200px;" |
    {
|
      "type": "page",
|}
      "target": "Main_Page",
      "label": "Hauptseite"
    },
    {
      "type": "pageWithSubpages",
      "target": "Category:Documentation",
      "label": "Dokumentation"
    },
    {
      "type": "pageWithLinkedPages",
      "target": "Help:Editing",
      "label": "Bearbeitungshilfe"
    }
  ]
}</syntaxhighlight>
 
==== Start export from CLI ====
Once your JSON file is ready, run the following command to start the export:
<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.


== Creating a page list for the export ==
==== Options (<code>options</code>): ====
The pages to be exported are defined in the wiki page that is shown as the <code>title</code> in the json-file. (In the example above, this is the page <code>PDF</code> .)


The page <code>PDF</code> now needs to list all pages  that will be exported to PDF.  
* <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.


This list can be created with an [[SMW queries|SMW inline query]] (BlueSpice free) or with a [[Manual:Extension/DynamicPageList3|DPL3 list]] (BlueSpice free).
==== 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>).


Example of an SMW query to create an export for all pages in the categories <code>Process</code> and <code>Work instruction</code>:<syntaxhighlight lang="text">
=== Automating with CronJob ===
==All processes==
To automate regular exports, set up a CronJob:
{{#ask:[[Process:+]]|format=ul|limit=99999}}
<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.


==All work instructions==
=== Migration from older format ===
{{#ask:[[Work instruction:+]]|format=ul|limit=99999}}
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:
</syntaxhighlight>The same list can be created with the following DPL3 syntax:<syntaxhighlight lang="text">
==All processes==
{{#dpl:category=Process}}


==All work instructions==
==== Old format ====
{{#dpl:category=Work instruction}}
<syntaxhighlight lang="json">{
</syntaxhighlight>
  "module": "pdf",
  "attachments": 1,
  "recursive": 1,
  "title": "MyPDF",
  "target": "localfilesystem",
  "target-file-name": "All.pdf",
  "target-file-path": "/path/to/target-file"
}</syntaxhighlight>


== Setting up a CronJob ==
==== New format ====
To automate the export, the following CronJob is available:<syntaxhighlight lang="text">
<syntaxhighlight lang="json">{
CronJob für Export
  "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>


php {MW_ROOT}/extensions/BlueSpiceUniversalExport/maintenance/export.php --specification-file={MW_ROOT}/extensions/BlueSpiceFoundation/data/notfall.json
==== Key changes ====
</syntaxhighlight>
{| 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.