在FPDI拆分后无法使用PDF2Text读取PDF

时间:2018-01-30 07:58:53

标签: php pdf fpdf

我正在拆分PDF文件,拆分后我想读取拆分页文本,但这并没有给我任何回报。如果我正在阅读之前,分裂是正常工作并返回所有PDF文本,但不知道为什么它在拆分后不起作用。这是我的代码: -

<?php

function split_pdf($filename, $end_directory = false)
{
require_once('../fpdf/fpdf.php');
require_once('../fpdi/fpdi.php');
require_once('../pdf2text/class.pdf2text.php');

$end_directory = $end_directory ? $end_directory : './';
$new_path = preg_replace('/[\/]+/', '/', $end_directory.'/'.substr($filename, 0, strrpos($filename, '/')));

if (!is_dir($new_path))
{
    // Will make directories under end directory that don't exist
    // Provided that end directory exists and has the right permissions
    mkdir($new_path, 0777, true);
}

$pdf = new FPDI();
$pagecount = $pdf->setSourceFile($filename); // How many pages?

// Split each page into a new PDF
for ($i = 1; $i <= $pagecount; $i++) {
    $new_pdf = new FPDI();
    $new_pdf->AddPage();
    $new_pdf->setSourceFile($filename);
    $new_pdf->useTemplate($new_pdf->importPage($i));

    try {

        $new_filename = $end_directory.str_replace('.pdf', '', $filename).'_'.$i.".pdf";
        $new_pdf->Output($new_filename, "F");
        echo "Page ".$i." split into ".$new_filename."<br />\n";

        $pdf2text = new PDF2Text();
        $pdf2text->setFilename($end_directory.$filename);
        $pdf2text->decodePDF();
        $text = $pdf2text->output();

        echo "This is page text =====>> ".$text."<br><br>";

    } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
}
}

// Create and check permissions on end directory!
split_pdf("test.pdf", 'split/');

?>

请帮助我,我不知道为什么会这样?

0 个答案:

没有答案