我正在使用 Framework7 ,并使用laravel 4.2生成pdf文件,但是当我单击按钮时,会在控制台上显示此文件:
下载完成:file:///data/user/0/com.aotour.driver/files/constancia_99469.pdf
但是什么也不要下载
$$('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代码
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);
});