In the application, we're trying to implement the fpdi to able to export the pdf that has a templated but it gives us an error
The versions of the ff
Laravel: 8.83.27
setasign/fpdf: "1.8",
setasign/fpdi: "^2.6",
Livewire component
<button wire:loading.remove wire:click.prevent='export' class="btn btn-warning text-white me-2">
<i class="bi bi-download"></i>
<span class='btn-text'>Export</span>
</button>
Controller
public static function export($data)
{
$period_month = date('n', strtotime($data['direct_payment']->date));
$get_year = date('Y', strtotime($data['direct_payment']->date));
$previos_quarter_month = Bir2307DateController::CheckBirPreviousMonth($period_month);
$period_from = date($previos_quarter_month.'01'.$get_year);
$last_quarter_month = app(Bir2307DateController::class)->CheckBirLastQuartMonth($period_month);
$last_day = cal_days_in_month(CAL_GREGORIAN, $last_quarter_month,strtotime('Y'));
$period_to = date($last_quarter_month.$last_day.$get_year);
// $period_to = date('mtY', strtotime($data['payments_others']->payment_date));
$period_from_split = str_split($period_from);
$period_to_split = str_split($period_to);
$vendor_tin = str_split($data['direct_payment']->vendorCustomer->tin);
$vendor_zip_code = str_split($data['direct_payment']->vendorCustomer->address_zip_code);
$vendor_address = $data['direct_payment']->vendorCustomer->address_street.", ".$data['direct_payment']->vendorCustomer->address_city.", ".$data['direct_payment']->vendorCustomer->address_province;
$company_tin = str_split($data['company']->tin);
$company_zip_code = ($data['company']->zip_code) ? str_split($data['company']->zip_code) : str_split("0000");
$company_address = $data['company']->street." ".$data['company']->brgy.", ".$data['company']->city.", ".$data['company']->province;
// $authorized_representative = static::getAuthorizedRepresentativeLength($data['company']->authorized_representative);
// $authorized_representative_position_tin = ($data['company']->authorized_representative_position_tin) ? '('.$data['company']->authorized_representative_position_tin.')' : '';
$pdf = new Fpdi();
$page_count = $pdf->setSourceFile(public_path()."/bir-form/bir-2307.pdf");
for ($pageNo = 1; $pageNo <= $page_count; $pageNo++) {
$tplIdx = $pdf->importPage($pageNo);
$pdf->AddPage();
$size = $pdf->getTemplateSize($tplIdx);
$width = $size["width"];
$height = $size["height"];
$pdf->useTemplate($tplIdx, 5, 5, 205,280);
// $pdf->useTemplate($tplIdx, 5, 5, 205);
// $pdf->useTemplate($tplIdx, 5, 5, $width,$height);
/* ==================== FOR THE PERIOD FROM ==================== */
if($pageNo == 1)
{
$pdf->SetFont('Times');
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFontSize(10);
$pdf->Text(57,41, $period_from_split[0]);
$pdf->Text(61,41, $period_from_split[1]);
$pdf->Text(66,41, $period_from_split[2]);
$pdf->Text(70,41, $period_from_split[3]);
$pdf->Text(74.5,41, $period_from_split[4]);
$pdf->Text(79,41, $period_from_split[5]);
$pdf->Text(83.5,41, $period_from_split[6]);
$pdf->Text(87.5,41, $period_from_split[7]);
}
}
return $pdf->Output('I','direct_payment.pdf');
}
Question: how to able to export using FPDI?
