DEV Community

loading...

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

pcmagas profile image Dimitrios Desyllas ・1 min read

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);

Discussion (1)

pic
Editor guide
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.