abcaeffchen / sepadocumentor Goto Github PK
View Code? Open in Web Editor NEWGenerate file routing slips and control lists as PDF for SEPA files
License: GNU Lesser General Public License v3.0
Generate file routing slips and control lists as PDF for SEPA files
License: GNU Lesser General Public License v3.0
While messing with the SepaDocumentor-class I ran into this error while generating the controllist-file:
The HTML code size is larger than pcre.backtrack_limit 1000000. You should use WriteHTML() with smaller string lengths.
This happens when you add too many payments to your SEPA-File. I don't know how much of an issue this really is as most people will never run into this problem.
But the funny thing is, that I ran into exactly the same problem with mPDF some time ago and the little workaround i'm using in my project can pretty much be used without any changes in SepaDocumentor.
Here is my modified mPDFWrapper-function. When it encounters a HTML-String that's too big, it splits it into chunks (while trying to make sure chunks end with a </tr>
if possible) and adds those chunks one after another to the PDF instead of one giant string.
The biggest issue is that this workaround might mess up the layout if you don't use tables and the str_split-function splits the HTML inside of CSS-definitions/HTML-Tags, etc.
Because of this problem I decided to not post this as a pull-request as it's kind of a "hacky" fix for the problem.
protected static function mPDFWrapper($html)
{
$pdf = new Mpdf();
$limit = (int)(ini_get('pcre.backtrack_limit') * 0.9);
if (strlen($html) > $limit) {
$chunks = str_split($html, $limit);
foreach ($chunks as $k=>$chunk) {
$last_tr = strripos($chunk, '</tr>'); // find last </tr>
if ($last_tr !== false) {
$last_tr = $last_tr + 5;
$leftover = substr($chunk, $last_tr);
if (isset($chunks[$k + 1])) {
$chunks[$k] = substr($chunks[$k], 0, $last_tr);
$chunks[$k + 1] = $leftover.$chunks[$k + 1];
}
}
}
foreach ($chunks as $k=>$chunk) {
$pdf->WriteHTML($chunk);
unset($chunks[$k]);
}
} else {
$pdf->WriteHTML($html);
}
return $pdf->Output('','S'); // returns the PDF as a string
}
I guess it would be better to use a custom str_split that makes sure to never split inside of html-tags but for my use-case this version works good enough.
The direct integration of mpdf does not allow to set the temp path, see https://mpdf.github.io/installation-setup/folders-for-temporary-files.html.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.