barryvdh / laravel-snappy

Laravel Snappy PDF
MIT License
2.63k stars 290 forks source link

Exit status code '-1073741819' when use <script> element and onload event in blade file #433

Closed yankotinuj closed 2 years ago

yankotinuj commented 3 years ago

Hello, I have a problem with laravel/snappy package when use javascript in header view file. It gives an error with status code '-107374819' which the code of header file copying from WKHTMLTOPDF Manual.

This is my setup : Windows 10 64 bit "barryvdh/laravel-snappy": "^0.4.8" "laravel/framework": "^8.0" wkhtmltopdf 0.12.6 (with patched qt) -> installed in Windows 10

This is my configuration in snappy.php

'pdf' => [
        'enabled' => true,
        'binary'  => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"',
        'timeout' => false,
        'options' => [
            'enable-local-file-access' => true
        ],
        'env'     => [],
    ],

This is the options in function to create the PDF

public function cetakSuratNotaPembayaranPajak($pdf_name, $formatPrint)
    {
        $disk = Storage::disk('nota_pembayaran_pajak');
        $pdf = WkhtmlPDF::loadView('nota_pembayaran_pajak.cetak.nota_pembayaran_pajakContent', ['format_print' => $formatPrint])
        ->setPaper('a4')->setOrientation('portrait')
        ->setOption('header-html', view('nota_pembayaran_pajak.cetak.nota_pembayaran_pajakHeader'))
        ->setOption('footer-html', view('nota_pembayaran_pajak.cetak.nota_pembayaran_pajakFooter'))
        ->setOption('margin-left', 15)
        ->setOption('margin-top', 30)
        ->setOption('margin-right', 15)
        ->setOption('margin-bottom', 25)
        ->setOption('enable-javascript', true)
        ->setOption('javascript-delay', 5000)
        ->setOption('enable-smart-shrinking', true)
        ->setOption('no-stop-slow-scripts', true)
        ->output();
        $disk->put($pdf_name, $pdf);
    }

And this is nota_pembayaran_pajakHeader file

<!DOCTYPE html>
<html>
    <head>
        <script>
            function subst() {
                var vars = {};
                var query_strings_from_url = document.location.search.substring(1).split('&');
                for (var query_string in query_strings_from_url) {
                    if (query_strings_from_url.hasOwnProperty(query_string)) {
                        var temp_var = query_strings_from_url[query_string].split('=', 2);
                        vars[temp_var[0]] = decodeURI(temp_var[1]);
                    }
                }
                var css_selector_classes = ['page', 'frompage', 'topage', 'webpage', 'section', 'subsection', 'date', 'isodate', 'time', 'title', 'doctitle', 'sitepage', 'sitepages'];
                for (var css_class in css_selector_classes) {
                    if (css_selector_classes.hasOwnProperty(css_class)) {
                        var element = document.getElementsByClassName(css_selector_classes[css_class]);
                        for (var j = 0; j < element.length; ++j) {
                            element[j].textContent = vars[css_selector_classes[css_class]];
                        }
                    }
                }
            }
        </script>
    </head>
    <body style="border:0; margin: 0;" onload="subst()">
        <table style="border-bottom: 1px solid black; width: 100%">
            <tr>
                <td class="section"></td>
                <td style="text-align:right">
                Page <span class="page"></span> of <span class="topage"></span>
                </td>
            </tr>
        </table>
    </body>
</html>

The error doesn't happen in header file only. Wherever there are <script> element and onload event in footer or view file, it will given message Exit status code '-1073741819'. Does anyway know about this problem? I've been looking for this issue for a week but haven't found any results and solve my problem. Your help will be appreciated. Thanks!

Agherrabi commented 3 years ago

me too i have the same problem This is very frustrating

yankotinuj commented 3 years ago

me too i have the same problem This is very frustrating

The documentation said that wkhtmltopdf support javascript but why it isn't work on me. I create new project and follow the step from this tutorial on section header with javascript, but still not work. I've been scan the filesystem of Windows 10 too because the error code -1073741819 only happen in Windows operating system as far as i know. CMIIW

yankotinuj commented 3 years ago

Hello again my friend. Yeah I still don't know why this is only happen in Windows. So, are you use html2pdf.js with laravel snappy/wkhtmltopdf? Thanks.

My english isn't good too, my friend :D Have a great day!

mgalante324 commented 3 years ago

I'm having the same issue. Any luck finding a solution?

andeeDev commented 3 years ago

Do you use artisan serve to run laravel project?

yankotinuj commented 3 years ago

Do you use artisan serve to run laravel project?

Yes i do. Is the problem on artisan serve which caused error code '-1073741819'?

thisisandreww commented 3 years ago

Same issue here

andeeDev commented 3 years ago

@yankotinuj , I have chaged artisan serve on apache webserver and this error doesn't bother me anymore

andeeDev commented 3 years ago

The issue is related to the way you started the application. With php artisan serve you get this type of error, but in case of using webserver javascript code will be executed without errors.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/KnpLabs/snappy instead. When having doubts, please try to reproduce the issue with just snappy. If you believe this is an actual issue with the latest version of laravel-snappy, please reply to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.