Parsing multiple PDFs from text input with PDF Parser library

526 views Asked by At

I'm attempting to use the PDF Parser PHP library to parse the text from multiple PDFs which are submitted through a form textarea (one PDF URL per line).

The code I'm using is:

<?php
include 'vendor/autoload.php';
$ids = $_POST["textarea"];
foreach(explode("\n", $ids) as $line) {
    $parser = new \Smalot\PdfParser\Parser();
    $pdf = $parser->parseFile($line);
    $text = $pdf->getText();            
    echo $text . '<br />';
?>

Note: 'vendor/autoload.php' is a Composer file.

This works as expected when I put only 1 URL into the textarea, but if I put more than one it returns nothing. I'm not sure if there's something wrong with my foreach loop or if this library does not support parsing multiple PDFs in a loop... Any advice is appreciated!

0

There are 0 answers