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

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

Closed
yankotinuj opened this issue May 19, 2021 · 10 comments
Labels

Comments

@yankotinuj
Copy link

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
Copy link

me too i have the same problem
This is very frustrating

@yankotinuj
Copy link
Author

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
Copy link
Author

yankotinuj commented May 31, 2021 via email

@mgalante324
Copy link

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

@andeeDev
Copy link

Do you use artisan serve to run laravel project?

@yankotinuj
Copy link
Author

Do you use artisan serve to run laravel project?

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

@thisisandreww
Copy link

Same issue here

@andeeDev
Copy link

andeeDev commented Aug 2, 2021

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

@andeeDev
Copy link

andeeDev commented Aug 5, 2021

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
Copy link

stale bot commented Oct 12, 2021

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.

@stale stale bot added the stale label Oct 12, 2021
@stale stale bot closed this as completed Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants