fix pdf creation for very large exports (#1533)

This commit is contained in:
Kevin Papst
2020-03-08 00:24:49 +01:00
committed by GitHub
parent d60e738bd2
commit ace2788b57
6 changed files with 54 additions and 25 deletions

View File

@@ -34,7 +34,21 @@ class MPdfConverter implements HtmlToPdfConverter
{
$mpdf = new Mpdf(['tempDir' => $this->cacheDirectory]);
$mpdf->creator = Constants::SOFTWARE;
$mpdf->WriteHTML($html);
// some OS do not follow the PHP default settings
if ((int) ini_get('pcre.backtrack_limit') < 1000000) {
@ini_set('pcre.backtrack_limit', 1000000);
}
// reduce the size of content parts that are passed to MPDF, to prevent
// https://mpdf.github.io/troubleshooting/known-issues.html#blank-pages-or-some-sections-missing
$parts = explode('<pagebreak>', $html);
for ($i = 0; $i < count($parts); $i++) {
$mpdf->WriteHTML($parts[$i]);
if ($i < count($parts) - 1) {
$mpdf->WriteHTML('<pagebreak>');
}
}
return $mpdf->Output('', Destination::STRING_RETURN);
}