Fpdi pdf-parser error message

  Wed 05 / 04 / 2023

  Posted by: OG Designs

Category : Laravel

Tags : laravel , php laravel , backend , deployment

Post Thumbnail
Description

I have a pdf template in my project so if am trying to download i got the below error message


View Code
                        <?php

namespace App\Http\Controllers;

use Carbon\Carbon;
use setasign\Fpdi\Fpdi;
use App\Models\Certificate;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;

class FillPDFController extends Controller


{
    public function process($id)

    {
        $certificate = Certificate::find($id);
        $outputfile = public_path().'dcc.pdf';
        $this->fillPDF(public_path().'/master/dcc.pdf',$outputfile,$certificate->name,$certificate->certificate_num);
       return response()->file($outputfile);
    }

    public function fillPDF($file,$outputfile,$nama,$certificate_num)
    {

        $rows = Certificate::orderBy('created_at','desc')->get();
        foreach ($rows as $row){
            "Certificate number for ID {$row->id} is: {$row->certificate_num}<br>";
        }
         {
        $fpdi = new FPDI;
        $fpdi->setSourceFile($file);
        $template = $fpdi->importPage(1);
        $size = $fpdi->getTemplateSize($template);
        $fpdi->AddPage($size['orientation'],array($size['width'],$size['height']));
        $fpdi->useTemplate($template);
        $top =98;
        $right = 105;
        $nama = $nama;
        $fpdi->SetFont("helvetica","",25);
        $fpdi->SetTextColor(25,26,25);
        $fpdi->Text($right,$top,$nama);
        $fpdi->ln();
       
        $top =30;
        $right = 232;
        $fpdi->SetFont("helvetica","",11);
        $fpdi->Text($right,$top,$certificate_num);

        $todayDate = Carbon::now()->format('F j, Y');
         //dd($todayDate);
        $top = 186;
        $right = 66;
        $fpdi->SetFont("helvetica","",12);
        $fpdi->Text($right,$top,$todayDate);


       //get the QRcode PNG  u generated
        $qrImage=storage_path('/app/public/img/qr-code/1680513790.png');

        // insert image at position x,y,w,h
        $fpdi->Image($qrImage,234,55,36,30);
        
        
        return $fpdi->Output($outputfile,'F');
        
    }

    }
    

    }
                
  Answered by CDL

The problem is in the pdf version, by downgrading the PHP version it will work.

Solved
  Comment   Share
0 Likes   2 Comments


comment-author
OG Designs Author

I am yet to solve the problem. I am still struggling to solve the problem



Reply


commented 1 year ago
comment-author
Hadayat Niazi Super Admin

For more information please visit the below link. https://stackoverflow.com/questions/12154190/fpdf-error-this-document-testcopy-pdf-probably-uses-a-compression-technique-w



comment-author
Hadayat Niazi Super Admin

You are using a paid version of pdf, switch to the free version which 1.4 or less then, it will resolve your problem



comment-author
Hadayat Niazi Super Admin

Yes, we got your query, Our team will fix your issue very soon. Thank you



Reply


commented 1 year ago
comment-author
OG Designs Author

I will be very happy if the issue is fix. Thank you in advance.