Closed abbe-cipher closed 7 years ago
Hi @abbe-cipher
You can simply use it by including the library with composer:
composer require tecnickcom/tcpdf
Then, have a look at their examples on GitHub (with a prettier version online).
Code seems to be quite old, but it still looks active and works.
Hi @noplanman thanks for your quick response.
your solution absolutely true and work. 💯 👍
i know this is not place to ask these kind of Question and this problem not related to telegrambot, but i have trouble with tcpdf library.
i added it to my project.and create new class under Longman\Telegrambot\ with Genpdf name :
<?php
namespace Longman\TelegramBot\tcpdf;
// use Longman\TelegramBot\tcpdf\TCPDF;
require( __DIR__ . '\tcpdf\tcpdf_include.php');
class Genpdf
{
public static function make()
{
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
. . . .
-----other code to create pdf file.
}
}
$s=new Genpdf();
$s->make();
i test it localy, when i comment namespace in thisclass all things right and generate a sample pdf file,but when uncomment namespace i give a error :
Fatal error: Uncaught Error: Class 'Longman\TelegramBot\tcpdf\TCPDF' not found in C:\xampp\htdocs\vendor\longman\telegram-bot\src\Genpdf.php:29 Stack trace: #0 C:\xampp\htdocs\vendor\longman\telegram-bot\src\Genpdf.php(96): Longman\TelegramBot\tcpdf\Genpdf::make() #1 {main} thrown in C:\xampp\htdocs\vendor\longman\telegram-bot\src\Genpdf.php on line 29
i put draw my project strucure blew :
[vendor] | [logman] |
---|
[telegrambot]
[src] |
---|
** Genpdf.class [tcpdf] | ** tcpdf.php class
Just use composer to include the TCPDF library! I assume you'll be using it within one of your commands, right? So the library will get autoloaded automatically.
As for your custom classes (for example Genpdf
), you will need to add the src
directory to be autoloaded via composer.json:
I suggest you make an own namespace for your project code (in the examples below I'll use Yaaay
)
{
"require": {
"tecnickcom/tcpdf": "^6.2"
...
},
"autoload": {
"psr-4": {
"Yaaay\\": "src/"
}
}
}
// src/Genpdf.php
<?php
namespace Yaaay;
use TCPDF;
class Genpdf
{
public function make()
{
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// etc...
}
}
Now, you can just make use of it by use
ing your Genpdf
class: 😃
// some file in your project
use Yaaay\Genpdf;
$s = new Genpdf();
$s->make();
Hope that gets you going.
I suggest you learn more about namespacing and PHP to understand how it works.
thank you so much @noplanman for your answer .
your are be patient and very modest man.
my problem solevd.
Required Information
Expected behaviour
i want to add tcpdf to my library. this library dont have namespace and thats my problem. clearly say ,i want to collect some data in survey and save it in pdf file and send to admin . what shoud i do ?
Actual behaviour
Steps to reproduce
Extra details