I'm using Framework7, and generating a pdf file using laravel 4.2 but when I click on the button it shows me the following error in console:
Download complete: file: ///data/user/0/com.aotour.driver/files/constancia_99469.pdf
and do not download anything, this is my code
$$('button').click(function(){
var servicio_id = $$(this).attr('data-id');
var fileTransfer = new FileTransfer();
var uri = encodeURI(urlserver+"descargarconstancia/"+servicio_id);
var fileURL = cordova.file.dataDirectory+'constancia_'+servicio_id+'.pdf';
fileTransfer.download(
uri,
fileURL,
function(entry) {
console.log("download complete: " + entry.toURL());
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("download error code" + error.code);
},
false,
{
headers: {
"Authorization": token
}
}
);
});
Laravel code
Route::get('descargarconstancia/{id}', function($id){
$servicio = Servicio::find($id);
$pdfName = 'constancia_'.$servicio->id.'.pdf';
$pdfPath = 'biblioteca_imagenes/constancias/';
$view = View::make('servicios.plantilla_constancia_vieja')->with(['servicio' => $servicio]);
$view = preg_replace('/>\s+</', '><', $view);
File::put($pdfPath.$pdfName, PDF::load($view, 'A4', 'portrait')->output());
header("Content-type:application/pdf");
return Response::download($pdfPath.$pdfName);
});