Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete text from PDF using FPDI/ FPDF

Tags:

php

pdf

fpdf

fpdi

I Want to edit PDF in php using FPDI/FPDF.I want to replace particular text.I have try many solution but they are not giving the desired result.All are writing some new text in new position. I want to search some text and replace that text with a new text.
Is This Possible?If yes please explain.
Code:

    require_once('fpdf.php');
    require_once('fpdi.php');

    $pdf =& new FPDI();
    $pdf->AddPage();


    //Set the source PDF file
    $pagecount = $pdf->setSourceFile("test.pdf");

    //Import the first page of the file
    $tpl = $pdf->importPage(1);
    //Use this page as template
    $pdf->useTemplate($tpl);



    //Go vertical position
    $pdf->SetY(15);
    //Select Arial italic 8
    $pdf->SetFont('Arial','I',8);
    //Print centered cell with a text in it
    $pdf->Cell(0, 10, "Hello World", 0, 0, 'C');

     //want something like this
     $pdf->replace("old_text","new_text");    

     $pdf->Output("my_modified_pdf.pdf", "F");
like image 653
Anand Singh Avatar asked Dec 05 '25 03:12

Anand Singh


1 Answers

It is not possible to edit a PDF document with FPDI and also it is not possible to replace text of an imported PDF page with FPDI.

like image 121
Jan Slabon Avatar answered Dec 07 '25 22:12

Jan Slabon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!