我正在尝试在 Codeigniter 中使用 PdfParser 库(PDFparser 链接),所以首先我已经下载、解压缩并安装了 third_party/vendor 文件夹下的库,另外我已经下载、解压缩并安装了 tcpdf 库在同一个 third_party /供应商文件夹。由于我无法在远程服务器上运行 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
有什么建议可以解决这个问题吗?非常感谢