smalot / pdfparser

PdfParser, a standalone PHP library, provides various tools to extract data from a PDF file.
GNU Lesser General Public License v3.0
2.42k stars 538 forks source link

codeigniter #122

Closed AfonsecaO closed 3 years ago

AfonsecaO commented 8 years ago

how can i load in Codeigniter?

ShutUpMagda commented 8 years ago

I've done with a library (see the docs). Just declare a class in your app libraries path like this:

<?php
class Pdfparser {
    function __construct() {
        require_once '/*path_to_pdfparser*/vendor/autoload.php';
    }
}

I'm loading it with autoload: $autoload['libraries'] = ['Pdfparser'];, but you also can load it manually.

Then, you can call it by a helper function (or a method in a controller), like this:

    function file_pdf_parser($file){
        $parser = new \Smalot\PdfParser\Parser();
        $pdf = $parser->parseFile($file);
        $text = $pdf->getText();
        return $text;
    }

Watch out the class name (Pdfparser ).

federicovilla commented 6 years ago

Sorry if I get back to this old post...but I'm not able to figure out how to install and use pdfparser in CI. First of all you should know that I cannot run composer on my remote server...so I'm trying to set all dependencies and files into my local WIndows PC, then upload what needed into the remote server. I've downloaded into my PC the pdfparser-master from github, unzipped it...opened the Windows Power Shell and performed the composer update command from inside the previously unzipped folder. After that I have uploaded into the remote server Codeigniter third_party folder the local vendor and src folder. I have created the library Pdfparser as suggest byt ShutUpMagda, below the code: class Pdfparser { function __construct() { require_once '/third_party/pdfparser/vendor/autoload.php'; } }

but when I try to load the library into my controller using $this->load->library('pdfparser');

I get the following error: [26-Oct-2018 07:42:20 UTC] PHP Fatal error: require_once(): Failed opening required '/third_party/pdfparser/vendor/autoload.php' (include_path='.:/opt/alt/php54/usr/share/pear:/opt/alt/php54/usr/share/php') in /home/gavsit/public_html/application/libraries/Pdfparser.php on line 6

Any help to fix this?

Thanks a lot