I'm generating PDF of html table. I want to save pdf in database. This script is downloading pdf. I want to send pdf file to controller side then save in database. I'm getting base64 string in controller now how i can save with url?
var doc = new jsPDF({
unit: 'px',
format: 'a4'
});
doc.fromHTML($('#revision_table').get(0), 2, 2);
doc.save('scdedule_revision.pdf');
var pdf = doc.output();
axios.post(this.$path + 'api/savePdf', null,
{
params: {'pdf_file': doc.output('datauri')}
}
).then(({data}) => (
console.log(data)
))
.catch(error => console.log(error));
Controller:
public function savePdf(Request $request)
{
$destinationPath = 'users/pdf';
$fileuploadedpath = '';
$pdf = $request->get('pdf_file');
if ($pdf != '') {
$extension = $pdf->getClientOriginalExtension();
$fileName = rand(11111, 99999) . '.' . $extension;
$success[0] = $pdf->move($destinationPath, $fileName);
$fileuploadedpath = url($destinationPath . "/" . $fileName);
}
dd($fileuploadedpath);
}
Actually you can save the data URI in the database as a string and then fetch it with axios
This is how you get the URI string:
doc.output('datauri')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.