Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(dev/core#574) Prevent memory exhaustion when generating large PDFs #13232

Merged
merged 1 commit into from
Nov 15, 2019
Merged
Changes from all commits
Commits
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
23 changes: 11 additions & 12 deletions CRM/Utils/PDF/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,20 @@ public static function html2pdf($text, $fileName = 'civicrm.pdf', $output = FALS
<div id=\"crm-container\">\n";

// Strip <html>, <header>, and <body> tags from each page

$htmlElementstoStrip = [
'@<head[^>]*?>.*?</head>@siu',
'@<script[^>]*?>.*?</script>@siu',
'@<body>@siu',
'@</body>@siu',
'@<html[^>]*?>@siu',
'@</html>@siu',
'@<!DOCTYPE[^>]*?>@siu',
'<head[^>]*?>.*?</head>',
'<script[^>]*?>.*?</script>',
'<body>',
'</body>',
'<html[^>]*?>',
'</html>',
'<!DOCTYPE[^>]*?>',
];
$htmlElementsInstead = ['', '', '', '', '', ''];
foreach ($pages as & $page) {
$page = preg_replace($htmlElementstoStrip,
$htmlElementsInstead,
$page
);
foreach ($htmlElementstoStrip as $pattern) {
$page = mb_eregi_replace($pattern, '', $page);
}
}
// Glue the pages together
$html .= implode("\n<div style=\"page-break-after: always\"></div>\n", $pages);
Expand Down