mercredi 24 avril 2019

Laravel 5.6 + wkhtmltopdf + snappy doesnt run javascript. I can't generate mathml correctly

I'm generating PDF from HTML which includes Mathml tags in Laravel 5.6 with barryvdh/laravel-snappy and wkhtmltopdf. I'm using Mathjax to compile Mathml tags properly. To compile Mathml with Mathjax i need to use js - MathJax.Hub.Queue(["Typeset",MathJax.Hub]); If I use this script in Laravel i get.

The exit status code '-1073741819' says something went wrong: stderr: "Loading pages (1/6) [> ] 0% [======> ] 10% [==============================> ] 50% Warning: Failed to load https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML (ignore) " stdout: "" command: "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" --dpi "200" --margin-bottom "0" --margin-left "0" --margin-right "0" --margin-top "0" --page-size "A4" --encoding "utf-8" --images --enable-javascript --javascript-delay "4000" --disable-smart-shrinking --no-stop-slow-scripts "C:\Users\x\AppData\Local\Temp\knp_snappy5cc0ba2f58c8b2.68931254.html" "x/5cc0ba2f4c5a5_2019-04-24.pdf".

Im using laravel 5.6

So here i have basic mathml tags and including javascript mathjax and basic process to generate mathml with Mathjax script

$txt = '<math><mn>2</mn><msup><mi>x</mi><mn>2</mn></msup></math>';
$html = $txt . '<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script><script>MathJax.Hub.Queue(["Typeset",MathJax.Hub]);</script>';
$arkuszId = uniqid();
$now = Carbon::now();
$now = $now->toDateString();
$fileName = $arkuszId . '_' . $now . '.pdf';
$folderToSave = 'storage/arkusze-pdfy/' . $fileName;

$options = array(
        'lowquality' => false,
        'encoding' => 'utf-8',
        'images' => true,
        'page-size' => 'A4',
        'dpi' => 200,
        'enable-javascript' => true,
        'javascript-delay' => 4000,
        'disable-smart-shrinking' => true,
        'margin-bottom' => '0',
        'margin-left' => '0',
        'margin-right' => '0',
        'margin-top' => '0',
);

$pdf = SnappyPDF::generateFromHtml($html, $folderToSave, $options);

When i using this script in core PHP everything works...

Please help me, cant resolve this error since few days...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire