mikehaertl / phpwkhtmltopdf

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface
MIT License
1.6k stars 238 forks source link

solve @error "QXcbConnection: Could not connect to display" #313

Closed ThomasTrovon closed 5 years ago

ThomasTrovon commented 5 years ago

@var boolean the value of var $enableXvfb in the Command() class instance:

----- public function getCommand(){ ... } -----

attributing TRUE value to this var, solve @error "QXcbConnection: Could not connect to display" in Debian systems like explained in the folowing "Question URL":

https://unix.stackexchange.com/questions/192642/wkhtmltopdf-qxcbconnection-could-not-connect-to-display

mikehaertl commented 5 years ago

I don't really get it. Command::$enableXvfb already defaults to false. And to enable it you can pass options via the commandOptions as explained here: https://github.com/mikehaertl/phpwkhtmltopdf#built-in-xvfb-support

As I see it, this change has no effect at all.

ThomasTrovon commented 5 years ago

I really created $ enableXvfb with default valuefalse, for the cases that do not want to change this to true. The use that I was doing, to change their value to true, it was this way:

! [image] (https://user-images.githubusercontent.com/10778234/55233279-7819a380-51fe-11e9-99be-609beeead6a8.png)

$pdf = new \mikehaertl\wkhtmlto\Pdf(view('rh::relatorio-ponto-rh.grupo_pdf', $data)->render());

$pdf->enableXvfb = true;

$name = now()->format('Y-m-d').'_'.Str::random().'.pdf';
$url = storage_path('app/public/temporarios/'.$name);

$pdf->saveAs($url);

But you are right. I can use the var $commandOptions like this:

! [image] (https://user-images.githubusercontent.com/10778234/55233405-e2cadf00-51fe-11e9-92a8-143af35ce41b.png)

$pdf = new \mikehaertl\wkhtmlto\Pdf(view('rh::relatorio-ponto-rh.grupo_pdf', $data)->render());

$pdf->commandOptions = [
    'enableXvfb' => true,
];

$name = now()->format('Y-m-d').'_'.Str::random().'.pdf';
$url = storage_path('app/public/temporarios/'.$name);

$pdf->saveAs($url);

I haven't seen your explanation about this. So when I got the error, and searched the internet, I tried to solve with my way.

Now, here, trying with your way, it worked out too.

xD

mikehaertl commented 5 years ago

Ok, so I think we can close this then.