I just have this same problem.
I install the package successfully and so far so good, but I try to generate the pdf with barryvdh/laravel-dompdf , but all my attempts have failed.
My ajax:
$.ajax({
type: 'post',
url: 'equipos/generarPdf',
global: false,
data: {
'data': data
},
}).then(
function(data) {
console.log("Documento Generado");
}, function(data) {
console.log('this will run if the $.ajax fails');
}, function() {
console.log('this will run if the deferred generates a progress update');
}
);
Note: in the execution of the ajax it returns me that there was no problem.
My route:
Route::post('equipos/generarPdf','EquiposController@generarPdf');
Note: As for the route, it recognizes me well.
My controller (generatePdf function):
public function generarPdf(Request $req) {
$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML('Test');
return $pdf->stream();
}
Note: when it gets here my app does nothing and I check network
Google Chrome and it returns the following:
Update 1:
I tried in different ways:
Here I load the file and run stream :
public function generarPdf(Request $req) {
$datos = $req->data;
$name_file = $datos[1].'-'.$datos[2].'.pdf';
$file_storage = storage_path('app\public\pdf\equipos\\').$name_file;
$file_public = public_path('storage\pdf\equipos\\').$name_file;
$pdf = \PDF::loadView('equipos.pdf_vista', $datos);
$pdf->setPaper('a4');
$pdf->setWarnings(false);
$pdf->save($file_storage);
return $pdf->loadFile($file_public)->stream($name_file);
}
Here I run stream :
public function generarPdf(Request $req) {
$datos = $req->data;
$name_file = $datos[1].'-'.$datos[2].'.pdf';
$file_storage = storage_path('app\public\pdf\equipos\\').$name_file;
$file_public = public_path('storage\pdf\equipos\\').$name_file;
$pdf = \PDF::loadView('equipos.pdf_vista', $datos);
$pdf->setPaper('a4');
$pdf->setWarnings(false);
$pdf->save($file_storage);
return $pdf->stream($name_file);
}
Here I download the file:
public function generarPdf(Request $req) {
$datos = $req->data;
$name_file = $datos[1].'-'.$datos[2].'.pdf';
$file_storage = storage_path('app\public\pdf\equipos\\').$name_file;
$file_public = public_path('storage\pdf\equipos\\').$name_file;
$pdf = \PDF::loadView('equipos.pdf_vista', $datos);
$pdf->setPaper('a4');
$pdf->setWarnings(false);
$pdf->save($file_storage);
return $pdf->download($name_file);
}
NOTE: the file is created in thepublica
Laravel folder but it does not generate the download of the file, for the 3 options I do not get an error, but in response I get the same as the previously exposed image.
Make sure your pdf is being generated correctly by creating a GET route and accessing it from the browser. Then try this.
[EDITED]
If it already returns the PDF symbols in the console log, the only thing you have wrong is your ajax. Use this:
If it still doesn't work, check in that console.log that strange characters don't appear in the PDF symbols. If they appear, you have to try combinations of utf8 encode and utf8 decode on the javascript and php side until it works.
recently I had a problem with it... and it was my version of php it turns out that in my case the laragon that replaces xampp was with version php 7.0 so you can review the documentation of dompdf and also see what version of php you are using and if er major because you will not be able to, you would have to change the version of php or create the project with a minor version of php the one that says in dompdf