0

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?

2 Answers2

3

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.

fusion3k
  • 11,568
  • 4
  • 25
  • 47
  • Thank you @fusion3k, I've tried your advice of using an absolute path and still no joy. I also tried using the files exactly as is (with all of the files inside the directory and it worked. Trouble is I'd like to use this code in a few locations on my website. I've tried including the example file that works when in it's own (tcpdf) directory [link](https://onlineticketseller.com/dist/tcpdf/examples/example_065.php) into a different file but it doesn't work. Any thoughts? Thank you –  Apr 05 '16 at 10:37
  • It **must** be work. You don't have to use example, but main tcpdf.php class file. Note that tcpdf directory must be inside your server document root or in php global include directory. What to you mean with “it doesn't work”? What error do you have? – fusion3k Apr 05 '16 at 10:43
  • Hi @fusion3k - sorry for being vague. 'It doesn't work' means it shows the server 500 error. It works so long as I only use files inside the tcpdf folder but if I try to use (include) a file from outside the folder it doesn't work (server 500) –  Apr 05 '16 at 12:30
  • When you see a 500 server error, you have to look at server log to understand the problem. – fusion3k Apr 05 '16 at 13:06
  • I saw that earlier in this post and have a had a look but can't find the error log. I've followed kb plesk instructions and found an empty log file and gave up. Frustrating!! –  Apr 05 '16 at 14:22
  • This a very big problem for you. Developing code without a way to see errors is really frustrating. I recommend you to investigate it or open a specific question about this: you need of know the errors! You can not test your php files in local environment? By this way, at least you can fix parse errors (every programmer makes a lot of parse error...) – fusion3k Apr 05 '16 at 14:29
  • I've managed to ssh into my server and see the last 100 entries to the error_log (yay!). I didn't find 'Fatal error: Class 'TCPDF' not found' or anything similar. Also, even though I just refreshed the page to see the error again then ran the command in ssh again the last entry was 4 hours ago and didn't look related, I'm sure I've taken up enough of your time, thank you for your help! –  Apr 05 '16 at 19:48
  • Last go? Can you please have a look at my edit? I made a little progress... maybe... –  Apr 05 '16 at 20:11
  • You persist to include `tcpdf_include.php` inside example directory: this file is intended for example files, so it doesn't work outside this directory. If you want use TCPDF class, you have to include correct class file: `tcpdf.php` in main TCPDF directory. – fusion3k Apr 05 '16 at 20:25
  • That's got rid of that error, now it says Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier..... ....tcpdf/include/tcpdf_static.php on line 396 I don't know what that means and Google isn't returning anything promising. Line 396 is: return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\''; –  Apr 05 '16 at 21:05
  • Yeah, if you are used coding w/out error reporting enabled, now you will see a lot of warnings! The timezone warning is not related to tcpdf, it appear each time you invoke a date/time function (see [this question](http://stackoverflow.com/questions/16765158/date-it-is-not-safe-to-rely-on-the-systems-timezone-settings)). But now finally your class is loaded!... – fusion3k Apr 05 '16 at 21:25
  • Holy cow - a pdf doc has just loaded! You are a very patient lovely person, thank you. –  Apr 05 '16 at 21:28
0

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);
BendaThierry.com
  • 2,080
  • 1
  • 15
  • 17
  • 1
    The last parameter is completely valid (see [docs](http://www.tcpdf.org/doc/code/classTCPDF.html#a134232ae3ad1ec186ed45046f94b7755) for details). – fusion3k Apr 04 '16 at 23:32