laravel-browsershot icon indicating copy to clipboard operation
laravel-browsershot copied to clipboard

Does this package work with Vue generated pages

Open RTSchriner opened this issue 4 years ago • 4 comments

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

RTSchriner avatar Aug 18 '20 17:08 RTSchriner

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();

benlbrm avatar Jan 04 '21 20:01 benlbrm

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

RTSchriner avatar Jan 05 '21 14:01 RTSchriner

@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 avatar Jan 18 '21 09:01 seyfer

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.

seyfer avatar Jan 18 '21 09:01 seyfer