Write generated HTML into Mpdf in chunks, rather than as one gigantic string

Due to a limitation in Mpdf, the HTML string passed to its WriteHTML method
must not exceed a particular length. PhpSpreadsheet produces one HTML string
containing all spreadsheet data when writing to HTML, which can easily exceed
Mpdf's size limit. Thus, it was impossible to write large spreadsheets to PDF
using the Mpdf writer - this change fixes that issue.

Fixes #637
Fixes #706
This commit is contained in:
Danielle McLean 2018-10-08 09:21:53 +11:00 committed by Adrien Crivelli
parent 3be06a5e87
commit 6703624223
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
2 changed files with 7 additions and 5 deletions

View File

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Csv reader avoid notice when the file is empty - [#743](https://github.com/PHPOffice/PhpSpreadsheet/pull/743) - Csv reader avoid notice when the file is empty - [#743](https://github.com/PHPOffice/PhpSpreadsheet/pull/743)
- Fix print area parser for XLSX reader - [#734](https://github.com/PHPOffice/PhpSpreadsheet/pull/734) - Fix print area parser for XLSX reader - [#734](https://github.com/PHPOffice/PhpSpreadsheet/pull/734)
- Support overriding `DefaultValueBinder::dataTypeForValue()` without overriding `DefaultValueBinder::bindValue()` - [#735](https://github.com/PHPOffice/PhpSpreadsheet/pull/735) - Support overriding `DefaultValueBinder::dataTypeForValue()` without overriding `DefaultValueBinder::bindValue()` - [#735](https://github.com/PHPOffice/PhpSpreadsheet/pull/735)
- Mpdf export can exceed pcre.backtrack_limit - [#637](https://github.com/PHPOffice/PhpSpreadsheet/issues/637)
## [1.5.0] - 2018-10-21 ## [1.5.0] - 2018-10-21

View File

@ -79,11 +79,12 @@ class Mpdf extends Pdf
$pdf->SetKeywords($this->spreadsheet->getProperties()->getKeywords()); $pdf->SetKeywords($this->spreadsheet->getProperties()->getKeywords());
$pdf->SetCreator($this->spreadsheet->getProperties()->getCreator()); $pdf->SetCreator($this->spreadsheet->getProperties()->getCreator());
$pdf->WriteHTML( $pdf->WriteHTML($this->generateHTMLHeader(false));
$this->generateHTMLHeader(false) . $html = $this->generateSheetData();
$this->generateSheetData() . foreach (\array_chunk(\explode(PHP_EOL, $html), 1000) as $lines) {
$this->generateHTMLFooter() $pdf->WriteHTML(\implode(PHP_EOL, $lines));
); }
$pdf->WriteHTML($this->generateHTMLFooter());
// Write to file // Write to file
fwrite($fileHandle, $pdf->Output('', 'S')); fwrite($fileHandle, $pdf->Output('', 'S'));