1

I am trying to use Pdfparser library to parse a PDF file but I have some issues with classes inclusion.

I read the documentation but it doesn't works.

I use Windows and XAMPP.

  • I created a directory in /xampp/htdocs/pdf_import
  • I installed Composer and I've generated the /vendor/autoload.php in pdfparser-master/src
  • I use the code example in documentation

Example:

<?php

require 'vendor/autoload.php';

// Parse pdf file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();
$pdf    = $parser->parseFile('document.pdf');

// Retrieve all pages from the pdf file.
$pages = $pdf->getPages();

// Loop over each page to extract text.
foreach ($pages as $page) {
    echo $page->getText();
}

When I run the php script I obtain this error:

Fatal error: Class 'Smalot\PdfParser\Parser' not found in C:\xampp\htdocs\pdf_import\pdfparser-master\src\import.php on line 8

hakre
  • 193,403
  • 52
  • 435
  • 836
bit
  • 427
  • 1
  • 6
  • 14
  • Use `require` instead of `include`. - See as well [Difference between “include” and “require” in php](http://stackoverflow.com/q/3633900/367456) – hakre Dec 24 '14 at 10:21
  • by using require I have not differences – bit Dec 24 '14 at 10:23
  • But you have the certainty that the `vendor/autoload.php` file has been loaded. I merely suggested it for that reason not that you trouble-shoot at a wrong end. – hakre Dec 24 '14 at 10:29
  • So, to further progress on this: Which part of the error message do you have questions about? What actually is your question? – hakre Dec 24 '14 at 10:36
  • In which directory did you exectue the `composer update smalot/pdfparser` command from the docs? – hakre Dec 24 '14 at 10:41
  • I tried to execute composer update from pdfparser-master/ and from pdfparser-master/src (moving all files). My question is why I have this errors. Probably is for this reason I cannot able to parse pdf file – bit Dec 28 '14 at 16:10

1 Answers1

0

Somehow your path is not good for

require 'vendor/autoload.php';

Verify if autoload is actually included.

In Codeigniter3/4 be sure you put the path in your config file

$config['composer_autoload'] = 'vendor/autoload.php';

then in your controller/library

    // Parse pdf file and build necessary objects.
    $parser = new \Smalot\PdfParser\Parser();
    $pdf    = $parser->parseFile(FCPATH . 'includes/temp/' . $pdf_file);
    
    return $pdf->getText();
Adrian P.
  • 5,060
  • 2
  • 46
  • 47