I just have this problem.
I install the package correctly and all right up there, but I try to generate the pdf with barryvdh / laravel-dompdf , but all my attempts have been unsuccessful.
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 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 driver (function generatePdf):
public function generarPdf(Request $req) {
$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML('Test');
return $pdf->stream();
}
Note: When you arrive here, my app does nothing and I check in network
of Google Chrome and it returns the following:
Update 1:
I tried different ways:
Here I will upload the file and execute 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 is 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 the folder publica
of laravel but does not generate the download of the file, for the 3 options I do not get an error, but rather in response I get the same as the image above.