DEV Community

Dimitrios Desyllas
Dimitrios Desyllas

Posted on

I managed to parse a pdf using Smalot\PdfParser but how I can construct it back?

I am parsing a pdf file and changing its text:

    $parser = new \Smalot\PdfParser\Parser()
    $pdf    = $parser->parseFile(storage_path().'/contracts/hello.pdf');
    
    // Retrieve all pages from the pdf file.
    $pages  = $pdf->getPages();
    
    $final = "";

    // Loop over each page to extract text.
    foreach ($pages as $page) {
        $text = $page->getText();
        $text = str_replace("\${NAME}","ΜΙΤΣΟΣ",$text);

Top comments (1)

Collapse
 
thefern profile image
Fernando B 🚀

I don't know this library, but I would try to do a try catch and see if there are any errors. I tried looking up the library documentation but is pretty limited.