vendredi 3 septembre 2021

read pdf with php and PDF2Text or pdf-to-text (spatie)

i´m traying to extract text from my PDF with class PDF2Text or spatie/pdf-to-text but i can´t to do... i´m traying first with:

PDF2Text

if($request->file('adjunto') != ""){

                $fileName = $request->file('adjunto')[0]->getClientOriginalName();

                $ext = pathinfo($fileName, PATHINFO_EXTENSION);
    
                $name = $fileName;
                $result = $request->file('adjunto')[0]->storeAs('importaciones', $name, 'public');
    
                $route =  public_path('storage/importaciones/'.$name);
    
            }else{
                return "Error al subir fichero, consulte al administrador del sistema";
            }

            if ($ext == "pdf" || $ext == "PDF"){
                $a = new PDF2Text();
                $a->setFilename($route);
                $a->decodePDF();
                echo $a->output();
            }else{

this else it´s for read CSV files. This code in block if PDF return empty result. And if i tray with

spatie library:

if($request->file('adjunto') != ""){

                $fileName = $request->file('adjunto')[0]->getClientOriginalName();

                $ext = pathinfo($fileName, PATHINFO_EXTENSION);
    
                $name = $fileName;
                $result = $request->file('adjunto')[0]->storeAs('importaciones', $name, 'public');
    
                $route =  public_path('storage/importaciones/'.$name);
    
            }else{
                return "Error al subir fichero, consulte al administrador del sistema";
            }

            if ($ext == "pdf" || $ext == "PDF"){
                $text = (new Pdf())
                        ->setPdf($route)
                        ->text();
                echo $text;
            }else{

return this:

Error Output:
================

    El sistema no puede encontrar la ruta especificada.
     {"userId":60,"exception":"[object] (Spatie\\PdfToText\\Exceptions\\CouldNotExtractText(code: 0): The command \"\"/usr/bin/pdftotext\" \"C:\\xampp\\htdocs\\gdsRepository\\public\\storage/importaciones/VIZNAR.PDF\" -\" failed.
    
    Exit Code: 1(General error)
    
    Working directory: C:\\xampp\\htdocs\\gdsRepository\\public
    
    Output:
    ================

if i tray with $fileName not $route

return this: local.ERROR: could not find or read pdf 'x.pdf' for my application i´m using laravel 5.6

mi PDF it´s:

enter image description here

i need 'nombre'(name), 'domicilio'(address), 'telefonos'(phone)

in this link, have pdf example:

https://drive.google.com/file/d/14uz4_sRphrOVvziv6n6_illb778WkETl/view?usp=sharing

Thanks for read and thanks for help me, please



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3zUr1dO
via IFTTT

Aucun commentaire:

Enregistrer un commentaire