Reputation: 661
I have one issue and I would like to know how to fix it. I have an api that returns base64 pdfs:
{
"resp_1": "JWETRi0xLjMNCiXi48/TDQoNCjEgMCB.....",
"resp_2": "RTGHEgi0xLhjhjjjDQoNCjEgMCB.....",
}
I need to merge them into one file and upload them to S3, for uploading files there is no problem, but the issue here is merging. I am trying this:
...
use Webklex\PDFMerger\Facades\PDFMergerFacade as PDFMerger;
....
....
//$resp_1 is JWETRi0xLjMNCiX.....
$file_encoded = base64_decode($resp_1);
$file_encoded_2 = base64_decode($resp_2);
$oMerger = PDFMerger::init();
$oMerger->addPDF(mb_convert_encoding($file_encoded, 'UTF-8', 'UTF-8'), 'all');
$oMerger->addPDF(mb_convert_encoding($file_encoded_2, 'UTF-8', 'UTF-8'), 'all');
$oMerger->merge();
$oMerger->save(public_path('storage/merged.pdf'));
.....
{ "message": "Could not locate PDF on '%PDF-1.3\r\n%????......."
"file": "D:\test\vendor\webklex\laravel- pdfmerger\src\PDFMerger\PDFMerger.php", "line": 184, "trace": [
What can I do?
Upvotes: 0
Views: 812
Reputation: 304
Use addString
method instead of addPDF
(addPDF
accept a path to file as an argument):
$oMerger->addString('raw file data', 'all');
Upvotes: 1