Codeigniter中的PdfParser

时间:2018-10-26 15:12:54

标签: php codeigniter pdfparser

我试图在Codeigniter中使用PdfParser库(PDFparser link),因此首先我下载了​​该库,并解压缩并将其安装在third_party / vendor文件夹下,另外我还下载了该库,并将其解压缩并安装了 tcpdf库位于相同的third_party / vendor文件夹中。 由于我无法在远程服务器上运行Composer,因此已在thir_party / vendor文件夹中创建了一个autoload.php文件。 现在,文件夹结构如下:

third_party
   vendor
      autoload.php
      tecnickcom
         tcpdf
      smalot
         pdfparser
            src
               Smalot
                  PdfParser

自动加载文件中用于加载所有依赖项的代码如下:

    $vendorDir = '../vendor';
$tcpdf_files = Array(
    'Datamatrix' => $vendorDir . '/tecnickcom/tcpdf/include/barcodes/datamatrix.php',
    'PDF417' => $vendorDir . '/tecnickcom/tcpdf/include/barcodes/pdf417.php',
    'QRcode' => $vendorDir . '/tecnickcom/tcpdf/include/barcodes/qrcode.php',
    'TCPDF' => $vendorDir . '/tecnickcom/tcpdf/tcpdf.php',
    'TCPDF2DBarcode' => $vendorDir . '/tecnickcom/tcpdf/tcpdf_barcodes_2d.php',
    'TCPDFBarcode' => $vendorDir . '/tecnickcom/tcpdf/tcpdf_barcodes_1d.php',
    'TCPDF_COLORS' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_colors.php',
    'TCPDF_FILTERS' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_filters.php',
    'TCPDF_FONTS' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_fonts.php',
    'TCPDF_FONT_DATA' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_font_data.php',
    'TCPDF_IMAGES' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_images.php',
    'TCPDF_IMPORT' => $vendorDir . '/tecnickcom/tcpdf/tcpdf_import.php',
    'TCPDF_PARSER' => $vendorDir . '/tecnickcom/tcpdf/tcpdf_parser.php',
    'TCPDF_STATIC' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_static.php'
);

foreach ($tcpdf_files as $key => $file) {
    include_once $file;
}

include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Parser.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Document.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Header.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Object.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Page.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Pages.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementArray.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementBoolean.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementString.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementDate.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementHexa.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementMissing.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementName.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementNull.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementNumeric.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementStruct.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementXRef.php";

include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding/StandardEncoding.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding/ISOLatin1Encoding.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding/ISOLatin9Encoding.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding/MacRomanEncoding.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding/WinAnsiEncoding.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font/FontCIDFontType0.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font/FontCIDFontType2.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font/FontTrueType.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font/FontType0.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font/FontType1.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/XObject/Form.php";
include_once  $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/XObject/Image.php";

我已经在Codeigniter库文件夹中创建了一个新文件,该文件名为Pdfparser.php,其内容如下:

    defined('BASEPATH') OR exit('No direct script access allowed');

class Pdfparser {
    function __construct() {
        require_once APPPATH.'/third_party/vendor/autoload.php';
    }
}

在控制器中,我使用以下命令手动加载libray文件:

$this->load->library('pdfparser');

问题是,当我尝试使用

实例化类时
$parser = new \Smalot\PdfParser\Parser();

我收到以下错误:

PHP Fatal error:  Class 'Smalot\PdfParser\Parser' not found

是否有解决此问题的建议?非常感谢

1 个答案:

答案 0 :(得分:1)

我认为您使用版本控制吗?

通过composer在本地安装这些库(我看到您只是下载并解压缩了-无法使用)。只需使用vendor的常规目录结构即可。

您在项目根目录中应该有一个composer.jsoncomposer.lock。安装后,composer还会创建类映射文件等,以便找到您的类。

所以。您可以将供应商文件夹放入Git(这可能会有点混乱,具体取决于您运行作曲家命令的频率),也可以仅使用scp之类的工具将供应商文件安全地复制并部署到位。 / p>

希望这会有所帮助!