verumconsilium / laravel-browsershot

Browsershot wrapper for Laravel 5
MIT License
110 stars 19 forks source link

Does this package work with Vue generated pages #23

Open RTSchriner opened 4 years ago

RTSchriner commented 4 years ago

I can't get my Vue pages to load correctly with this package. Any help would be greatly appreciated, thanks!

benlbrm commented 3 years ago

I have the same problem, I loading a view with some vuejs components and nothing is loaded. return PDF::loadView('resultat-print', ['id' => $id]) ->waitUntilNetworkIdle() ->ignoreHttpsErrors() ->noSandbox() ->setDelay(5000) ->inline();

RTSchriner commented 3 years ago

@benlbrm: I had to switch to Puphpeteer (https://github.com/rialto-php/puphpeteer).

seyfer commented 3 years ago

@RTSchriner it works for me with the following flow

Build your Vue view for production. Let's say you built it in pdf.min.js.

In Laravel create view with HTML header and footer. Inside in <script src=""> include your pre-built pdf.min.js.

$view = View::make('pdf');

Then you do the following:

return PDF::loadHtml($view->render())
            ->format('A4')
            ->showBrowserHeaderAndFooter()
            ->hideHeader()
            ->footerHtml(View::make('pdf/footer')->render())
            ->margins(10, 10, 30, 10)
            ->download(sprintf(
                'my.pdf',
            ));

It will spin a node instance which will run your rendered HTML template in the browser. As you have in the template pdf.min.js included, which is a built Vue view/app, the browser will render it and then you get your PDF with Vue rendered.

seyfer commented 3 years ago

I think it is also possible to use PDF::loadUrl('http://some') instead and run your Vue view/app somewhere on the server secure from the public access.