Git Product home page Git Product logo

sepadocumentor's People

Contributors

abcaeffchen avatar rud5g avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

sepadocumentor's Issues

pcre.backtrack_limit - Error with large files (and a potential "fix")

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.