【问题标题】:i can't require tcpdf library我不能要求 tcpdf 库
【发布时间】:2015-10-08 15:54:57
【问题描述】:

我想在我的代码中使用 tcpdf 库。它只是一个样本,我用它来测试。 我在笔记本电脑中使用 wamp 服务器。我的项目名称是“mysite”。在项目中,我有一个名为:tcpdf 的文件夹,其中包含我刚刚下载的库。和另一个 php 文件: index.php 包含我的主要代码。只是它 ! 在我的浏览器中输入: loclhost/mysite 它给了我一个无法找到文件的错误: tcpdf_include 。 我相信这是一个简单的问题,但我不能处理它!请帮我。这是紧急情况。


    <php> 

    /**
    * Creates an example PDF TEST document using TCPDF
    * @package com.tecnick.tcpdf
    * @abstract TCPDF - Example: Removing Header and Footer
    * @author Nicola Asuni
    * @since 2008-03-04
    **  /

    // Include the main TCPDF library (search for installation path).
    require_once('tcpdf_include.php');

    // create new PDF document 
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,        'UTF-8', false);

    // set document information
   $pdf->SetCreator(PDF_CREATOR); 
   $pdf->SetAuthor('Nicola Asuni');
   $pdf->SetTitle('TCPDF Example 002');
   $pdf->SetSubject('TCPDF Tutorial');
   $pdf->SetKeywords('TCPDF, PDF, example, test, guide');

   // remove default header/footer
   $pdf->setPrintHeader(false);
   $pdf->setPrintFooter(false);

   // set default monospaced font
   $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

   // set margins
   $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

   // set auto page breaks 
   $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

   // set image scale factor
   $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

   // set some language-dependent strings (optional)
    if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

    // set font
    $pdf->SetFont('times', 'BI', 20);

    // add a page
    $pdf->AddPage();

    // set some text to print
    $txt = <<<EOD
TCPDF Example 002

Default page header and footer are disabled using setPrintHeader() and setPrintFooter() methods.
EOD;

// print a block of text using Write()
$pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_002.pdf', 'I');

//============================================================+
// END OF FILE
//============================================================+


----------

【问题讨论】:

  • 显示的错误是什么?包含所有文件吗?

标签: php html tcpdf


【解决方案1】:

您的代码在 index.php 文件所在的同一文件夹中查找 tcpdf_include.php 文件,但是您提到 tcpdf 库位于文件夹中,因此您需要更改 rquiere 语句以指向该位置tcpdf 文件夹内的文件,例如:

require_once 'path/to/tcpdf_include/within/tcpdf/folder';

【讨论】:

  • 嗨 rdgar 它可以工作,我对 require_once 没有任何问题。但在这一行中,我的服务器不知道 tcpdf 类。
  • 您好@mostafa,您能否发布导致错误的代码。您是否能够毫无问题地要求 tcpdf_include.php 文件?
  • 我所有的代码都是我在这里分享的代码。错误是这样的:解析错误:语法错误,意外''); ' (T_CONSTANT_ENCAPSED_STRING) 在 C:\wamp\www\test\index.php 第 31 行
猜你喜欢
  • 2016-11-07
  • 1970-01-01
  • 1970-01-01
  • 2018-08-13
  • 1970-01-01
  • 1970-01-01
  • 2022-06-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多