Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
01d4b86
updated mpdf to 8.2 (requires php 8.0 now)
splitbrain Sep 2, 2025
c5c184f
first start at refactoring
splitbrain Nov 17, 2025
b883aec
add toc handling
splitbrain Nov 17, 2025
1d334a8
handle debug writing
splitbrain Nov 17, 2025
8c4b141
remove a few now unused methods
splitbrain Nov 17, 2025
081fc33
Handle styles
splitbrain Nov 17, 2025
2bef96e
move page collecting into separate classes
splitbrain Nov 20, 2025
ac65d8f
remove some moved methods
splitbrain Nov 20, 2025
6afd336
remove obsolete template event
splitbrain Nov 20, 2025
293d84e
more refactoring
splitbrain Nov 24, 2025
0eefd8f
decouple renderer
splitbrain Nov 25, 2025
ab12f14
removed more obsolete methods from action plugin
splitbrain Nov 25, 2025
f77f381
fixed issues from first real run
splitbrain Nov 26, 2025
decfd8d
extract $INPUT dependencies out of Collector classes
splitbrain Nov 26, 2025
4c3a95e
reimplement ImageProcessor differently
splitbrain Nov 26, 2025
38ca8b2
updated tests for Media resolving
splitbrain Nov 26, 2025
c617724
update general test
splitbrain Nov 26, 2025
8f1c137
removed unneeded custom exception
splitbrain Nov 26, 2025
bbcdb3f
rewrite internal links. implements #526
splitbrain Nov 26, 2025
4526935
address some of the remaining FIXMEs
splitbrain Nov 26, 2025
5eabda9
fix additional blank page at the end
splitbrain Nov 26, 2025
b706c93
fixed remaining sort test
splitbrain Nov 26, 2025
32d393a
have collectors check for page existance
splitbrain Nov 26, 2025
b23d7b8
for exporting single pages do not rely on $ID
splitbrain Nov 26, 2025
9220075
Added tests
splitbrain Nov 26, 2025
5340eaf
rector and codesnifffer fixes
splitbrain Nov 26, 2025
fbe4e9d
remove obsolete book chapter handling in action
splitbrain Nov 26, 2025
7002812
extracted PDF generation and sending out of action
splitbrain Nov 26, 2025
7542e5b
some minor fixes based on PR feedback
splitbrain Nov 27, 2025
01a7083
Use attributes in config class to denote how to initialize them
splitbrain Nov 27, 2025
f200011
make PdfExportService reusable in debug mode
splitbrain Nov 27, 2025
a9e9f33
introduce a first test for rendering - testing numbered headlines
splitbrain Nov 27, 2025
bee95f0
Overhaul chapter/header counting in renderer
splitbrain Nov 27, 2025
b08d547
pass the Config object into the renderer
splitbrain Nov 27, 2025
c124fc5
Some more tests testing rendering functionality
splitbrain Nov 28, 2025
212a1ea
fix config attrbutes and extend tests
splitbrain Nov 28, 2025
837fcad
update MPDF downgrade log/psr
splitbrain Dec 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 0 additions & 96 deletions DokuPDF.class.php

This file was deleted.

123 changes: 25 additions & 98 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
use dokuwiki\Extension\Event;
use dokuwiki\Extension\EventHandler;
use dokuwiki\plugin\dw2pdf\MenuItem;
use dokuwiki\plugin\dw2pdf\src\Config;
use dokuwiki\plugin\dw2pdf\src\DokuPdf;
use dokuwiki\plugin\dw2pdf\src\Template;
use dokuwiki\plugin\dw2pdf\src\Writer;
use dokuwiki\StyleUtils;
use Mpdf\HTMLParserMode;
use Mpdf\MpdfException;

/**
Expand Down Expand Up @@ -423,20 +428,13 @@ protected function generatePDF($cachefile, $event)
}

//some shortcuts to export settings
$hasToC = $this->getExportConfig('hasToC');
$levels = $this->getExportConfig('levels');
$isDebug = $this->getExportConfig('isDebug');
$watermark = $this->getExportConfig('watermark');

// initialize PDF library
require_once(__DIR__ . "/DokuPDF.class.php");
$config = new Config($this->conf, $this->getDocumentLanguage($this->list[0]));
$mpdf = new DokuPDF($config);
$template = new Template($this->getConf('template'), $this->getConf('qrcodescale'));
$writer = new Writer($mpdf, $template);

$mpdf = new DokuPDF(
$this->getExportConfig('pagesize'),
$this->getExportConfig('orientation'),
$this->getExportConfig('font-size'),
$this->getDocumentLanguage($this->list[0]) //use language of first page
);

// let mpdf fix local links
$self = parse_url(DOKU_URL);
Expand All @@ -446,64 +444,12 @@ protected function generatePDF($cachefile, $event)
}
$mpdf->SetBasePath($url);

// Set the title
$mpdf->SetTitle($this->title);

// some default document settings
//note: double-sided document, starts at an odd page (first page is a right-hand side page)
// single-side document has only odd pages
$mpdf->mirrorMargins = $this->getExportConfig('doublesided');
$mpdf->setAutoTopMargin = 'stretch';
$mpdf->setAutoBottomMargin = 'stretch';
// $mpdf->pagenumSuffix = '/'; //prefix for {nbpg}
if ($hasToC) {
$mpdf->h2toc = $levels;
}
$mpdf->PageNumSubstitutions[] = ['from' => 1, 'reset' => 0, 'type' => '1', 'suppress' => 'off'];

// Watermarker
if ($watermark) {
$mpdf->SetWatermarkText($watermark);
$mpdf->showWatermarkText = true;
}

// load the template
$template = $this->loadTemplate();

// prepare HTML header styles
$html = '';
if ($isDebug) {
$html .= '<html><head>';
$html .= '<style>';
}

$styles = '@page { size:auto; ' . $template['page'] . '}';
$styles .= '@page :first {' . $template['first'] . '}';

$styles .= '@page landscape-page { size:landscape }';
$styles .= 'div.dw2pdf-landscape { page:landscape-page }';
$styles .= '@page portrait-page { size:portrait }';
$styles .= 'div.dw2pdf-portrait { page:portrait-page }';
$styles .= $this->loadCSS();

$mpdf->WriteHTML($styles, 1);

if ($isDebug) {
$html .= $styles;
$html .= '</style>';
$html .= '</head><body>';
}
$writer->startDocument($this->title);
$writer->cover();

$body_start = $template['html'];
$body_start .= '<div class="dokuwiki">';

// insert the cover page
$body_start .= $template['cover'];

$mpdf->WriteHTML($body_start, 2, true, false); //start body html
if ($isDebug) {
$html .= $body_start;
}
// FIXME where to move this?
if ($hasToC) {
//Note: - for double-sided document the ToC is always on an even number of pages, so that the
// following content is on a correct odd/even page
Expand All @@ -517,43 +463,24 @@ protected function generatePDF($cachefile, $event)
'outdent' => '1em',
'pagenumstyle' => '1'
]);
$html .= '<tocpagebreak>';

$mpdf->WriteHTML('<tocpagebreak>', HTMLParserMode::HTML_BODY, false, false);
}

// loop over all pages
$counter = 0;
$no_pages = count($this->list);
foreach ($this->list as $page) {
$template->setContext($page, $this->title, $rev, $date_at, $INPUT->server->str('REMOTE_USER', '', true));

$this->currentBookChapter = $counter;
$counter++;

$pagehtml = $this->wikiToDW2PDF($page, $rev, $date_at);
//file doesn't exists
if ($pagehtml == '') {
continue;
}
$pagehtml .= $this->pageDependReplacements($template['cite'], $page);
if ($counter < $no_pages) {
$pagehtml .= '<pagebreak />';
}

$mpdf->WriteHTML($pagehtml, 2, false, false); //intermediate body html
if ($isDebug) {
$html .= $pagehtml;
}
$writer->wikiPage($pagehtml);
}

// insert the back page
$body_end = $template['back'];

$body_end .= '</div>';

$mpdf->WriteHTML($body_end, 2, false); // finish body html
if ($isDebug) {
$html .= $body_end;
$html .= '</body>';
$html .= '</html>';
}
$writer->back();
$writer->endDocument();

//Return html for debugging
if ($isDebug) {
Expand Down Expand Up @@ -616,12 +543,12 @@ protected function loadTemplate()

// this is what we'll return
$output = [
'cover' => '',
'back' => '',
'html' => '',
'page' => '',
'first' => '',
'cite' => '',
'cover' => '', // cover page
'back' => '', // back page
'html' => '', // header/footer html sections
'page' => '', // pseudo CSS to register header/footers
'first' => '', // pseudo CSS to register first page header/footers
'cite' => '', // citation box html
];

// prepare header/footer elements
Expand Down
Loading