Converting PDF to string

lolalola picture lolalola · Jan 24, 2011 · Viewed 30.8k times · Source

How read PDF file and put content into string? Using PHP language.

Answer

Matthew Smith picture Matthew Smith · Jan 24, 2011

You could use something like pdftotext which comes with the Xpdf package on linux. The popen command can then be used to pipe the output of pdftotext into a string:

$mystring = "";
$fd = popen("/usr/bin/pdftotext blah.pdf","r");
if ($fd) {
    while (($myline = fgets($fd)) !== false) {
        $mystring .= $myline;
    }
}