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

Mpdf export can exceed pcre.backtrack_limit #637

Closed
00dani opened this issue Aug 17, 2018 · 3 comments
Closed

Mpdf export can exceed pcre.backtrack_limit #637

00dani opened this issue Aug 17, 2018 · 3 comments

Comments

@00dani
Copy link
Contributor

00dani commented Aug 17, 2018

This is:

- [x] a bug report
- [ ] a feature request
- [x] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

It should be possible to write large spreadsheets from PhpSpreadsheet to PDF, using the Mpdf writer. In order to achieve this, PhpSpreadsheet should pass HTML into Mpdf in reasonably-sized chunks using multiple calls to WriteHTML.

What is the current behavior?

After the Mpdf writer converts a spreadsheet to HTML, it passes the entirety of the spreadsheet as one big HTML string into Mpdf's WriteHTML method. The string size can easily exceed the PHP setting pcre.backtrack_limit if a larger spreadsheet is being rendered, causing Mpdf to throw an exception and refuse to write the PDF.

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

for ($row = 1; $row < 100; ++$row) {
    for ($col = 1; $col < 100; ++$col) {
        $sheet->getCellByColumnAndRow($col, $row)->setValue('foo bar baz');
    }
}

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Mpdf');
$writer->save('/dev/null');

Which versions of PhpSpreadsheet and PHP are affected?

I'm working with PHP 7.1.20 and PhpSpreadsheet 1.3.1, but I believe this issue still affects newer versions - the Mpdf writer in PhpSpreadsheet 1.4.0 still passes all the HTML as a single string, so the behaviour is unlikely to have changed.

@christheyounger
Copy link

Any update on this?

@PowerKiKi
Copy link
Member

Not the answer you are hoping for, but I believe this is limitation of mpdf, not PhpSpreadsheet. I would suggest you comment on mpdf/mpdf#287 and explain your use-case.

However if one of you were to submit a PR to fix this in PhpSpreadsheet, I would merge it.

Meanwhile I'll close the issue as it is not likely the core team would do anything about it in the foreseeable future.

@christheyounger
Copy link

Righteo, we will attempt a workaround PR.

PowerKiKi pushed a commit that referenced this issue Nov 3, 2018
… 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
guillaume-ro-fr pushed a commit to guillaume-ro-fr/PhpSpreadsheet that referenced this issue Jun 12, 2019
… 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 PHPOffice#637
Fixes PHPOffice#706
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants