Dear Friends,
I am using TCPDF to merge different category PDF from folders to a single one. But with some PDF's I got error as TCPDF_PARSER ERROR: decodeFilterFlateDecode: invalid code.
My controller class code is
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Session;
use App\Models\ApplicationModel;
use DB;
use App\Models\NotificationsModel;
use App\Models\PostModel;
use PDF;
use LynX39\LaraPdfMerger\Facades\PdfMerger;
class ApplicationsController extends Controller
{
public function ViewApplnPDF(Request $request)
{
if(Session::has('role'))
{
$pdfMerger = PDFMerger::init();
$applnId = base64_decode($request->appln_id);
$applicantData = DB::table("ksrtc_applications")->where('ksrtc_applications.id',$applnId)
->select('ksrtc_applications.*','ksrtc_applications.created_at as submitted_date','ksrtc_post.*')
->join('ksrtc_post', 'ksrtc_applications.post_id', '=', 'ksrtc_post.id')
->first();
$education = DB::table("ksrtc_app_education")->where('app_id',$applnId)->get()->toArray();
$workExp = DB::table("ksrtc_work_experience")->where('app_id',$applnId)->get()->toArray();
$addlQuali = DB::table("ksrtc_addl_qualification")->where('app_id',$applnId)->get()->toArray();
$applicantPhoto = "applicant_photo/".$applicantData->photo;
$arrayP = [
'applicant'=> $applicantData,
'education' => $education,
'addlQuali' => $addlQuali,
'workExp' => $workExp,
'applicant_photo' => $applicantPhoto
];
$pdf = PDF::setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true,'chroot' => public_path()])->loadView('admin/ViewApplicationPdf', $arrayP);
$pdf->save(public_path('applicant_personal_details/appln_'.$applnId.'.pdf'));
$pdfMerger->addPDF(public_path('applicant_personal_details/appln_'.$applnId.'.pdf'));
$pdfMerger->addPDF(public_path('applicant_photo_id/'.$applicantData->identification_document));
foreach($education as $e)
{
$pdfMerger->addPDF(public_path('educational_qualification/'.$e->edn_certificate));
}
foreach($workExp as $w)
{
$pdfMerger->addPDF(public_path('work_experience/'.$w->exp_certificate));
}
foreach($addlQuali as $q)
{
$pdfMerger->addPDF(public_path('additional_qualification/'.$q->addl_certificate));
}
$pdfMerger->merge();
$pdfMerger->save(public_path('applicant_view_pdf/appln_'.$applnId.'.pdf'));
return response()->file('applicant_view_pdf/appln_'.$applnId.'.pdf');
return PDF::setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true,'chroot' => public_path()])
->loadView('admin/ViewApplicationPdf',$arrayP)->stream('Application_PDF.pdf');
}
else
{
return view('admin/AdminLoginForm');
}
}
}
I need to check the files are good for merging before get that ERROR.
example : in the code
foreach($workExp as $w)
{
$pdfMerger->addPDF(public_path('work_experience/'.$w->exp_certificate));
}
I need to check each file in code to find it's good or bad. If BAD omit that file and continue with GOOD files for merging .
Please help
Thanks
Anes