I've been trying to set up this php pdf script. I downloaded the code from the website and uploaded it as is from this page [https://sourceforge.net/projects/tcpdf/files/][1]
It works until the line that starts $pdf - I added echo $filename line to see if I could see errors (an idea found on this website - the page displays 1hello - I gather this probably means the require_once works OK.
<?
// Include the main TCPDF library (search for installation path).
$filename = require_once('../tcpdf/examples/tcpdf_include.php');
echo $filename.'hello';
exit;
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
etc. etc.
If I remove $filename = and the echo / exit line (below) I get a generic server 500 error - any ideas how to get a detailed error I can actually use? I can see detailed errors on other pages.
<?
// Include the main TCPDF library (search for installation path).
require_once('../tcpdf/examples/tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
etc. etc.
EDIT: Found the error by adding ini_set('display_errors', 1); to the page - the error is Fatal error: Class 'TCPDF' not found...on line 31
Line 31 refers to:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
If I look in the tcpdf_include.php include file it says some code that refers to some files I don't think my server has:
$tcpdf_include_dirs = array(
realpath('../tcpdf.php'),
'/usr/share/php/tcpdf/tcpdf.php',
'/usr/share/tcpdf/tcpdf.php',
'/usr/share/php-tcpdf/tcpdf.php',
'/var/www/tcpdf/tcpdf.php',
'/var/www/html/tcpdf/tcpdf.php',
'/usr/local/apache2/htdocs/tcpdf/tcpdf.php' );
/usr/share/php/ is empty. I'm guessing I should put the tcpdf.php file in all of those locations or does it not matter & I'm missing the point?
You can find detailed 500 server error in your web server (Apache?) logs. The location of logs depends of your OS/installation.
You gather fine: 1hello
means that the required file is loaded correctly. You don't need to check it, because if require
/require_once
fails, you get a Fatal Error, and the script dies.
If you can track down server error logs, probably you will see something like:
Fatal error: Class 'TCPDF' not found
because tcpdf/examples/tcpdf_include.php is intended to be used with provided examples, and it works correctly only if the main URL (or the current directory, if you execute the script via commandline) is in the same directory.
To load TCPDF class, you have to
require_once( '../tcpdf/tcpdf.php' );
but I suggest you to indicate absolute path.
These TCPDF constructor does not exist. You have added a boolean variable at the end, which is not allowed lol.
The following is better :
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);