How can I send PDF file from my angular fronted to my laravel backend

断了今生、忘了曾经 提交于 2019-12-08 14:38:22

It depends on how you convert your page to pdf. If you use addHtml(), your datauristring starts with something like this data:application/pdf;base64. But if you use newer version jsPDF and html(), then your datauristring is slightly different and will look like this data:application/pdf;filename=generated.pdf;base64,. Note that a new string filename=generated.pdf; is added to it. So make sure you decode the datauristring correctly.

I use .NET to decode my datauristring, not sure if it will be helpful to you since you are using php.

var match = Regex.Match(strJson, @"data:application/pdf;filename=generated.pdf;base64,(?<data>.+)");
var base64Data = match.Groups["data"].Value;
// or simply strJson.Replace("data:application/pdf;filename=generated.pdf;base64,", "");
var binData = Convert.FromBase64String(base64Data);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!