1

I need to integrate TCPDF as third party library in Symfony 2.1.

I tried in composer.json like

"repositories": [
    {
        "type": "vcs",
        "url": "git://tcpdf.git.sourceforge.net/gitroot/tcpdf/tcpdf"
    }
],
"require": {
    "tcpdf/tcpdf":"*"
},

But it gives an error The requested package tcpdf * could not be found.

How to give third party libraries correct in composer.json file?

TCPDF library don't follow namespaces, so how we can access this library in our bundle?

Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
Justin John
  • 9,223
  • 14
  • 70
  • 129

3 Answers3

5

The reason it's not found is that the package name in the tcpdf repo is tecnick.com/tcpdf, so that's what you should require.

That said, since it's available on packagist you don't need to add the vcs repository at all in your composer.json.

Seldaek
  • 40,986
  • 9
  • 97
  • 77
  • Thanks. How we can directly access tcpdf lib in our custom bundle? How we can create a tcpdf instance in AppKernel? – Justin John Sep 26 '12 at 06:06
  • `new TCPDF()` or whatever the classname is you want to instantiate should just work once the package is installed, it will be autoloadable. – Seldaek Sep 26 '12 at 17:49
  • When running this command `php composer.phar update`, `tecnick.com/tcpdf` is cloned. After that it waits for some time without showing anything in command prompt and display an error message `[RuntimeException] The process timed out.` I have added `new TCPDF()` in AppKernel, but it gives me an error `Class 'TCPDF' not found`. I edited file `/vendor/composer/autoload_real.php` and added a line `require $vendorDir . '/tecnick.com/tcpdf/tcpdf.php';` . It gives me an error `Call to undefined method TCPDF::getName()`. So I think autoload is not worked correctly. – Justin John Sep 27 '12 at 05:52
  • 2
    That looks like it timed out and did not finish the clone.. Try again and maybe also look into changing the process-timeout setting if you have a slow connection, see http://getcomposer.org/doc/04-schema.md#config – Seldaek Sep 27 '12 at 21:54
  • I don't know what is happening, after increasing process-timeout setting to 1000, same error persists. Please check my [composer.json and error in console](http://pastebin.com/b3LN1zHJ) – Justin John Sep 28 '12 at 04:49
0

There are several packages related to TCPDF on Packagist — some of them are bundles to integrate it with Symfony.

Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133
  • I am looking for bundle supports symfony version `2.1`. But I don't see anything perfect for this. – Justin John Sep 25 '12 at 09:29
  • I use "tcpdf/tcpdf": "dev-master" in my composer.json. In my app/autoload.php: require_once __DIR__.'/../vendor/tcpdf/tcpdf/tcpdf.php'; Then I wrote an own Helper class that extends \ TCPDF. It works. – stwe Sep 28 '12 at 20:02
-1

Since tcpdf does not support composer you need to use the package repository. The docs for this is available at:

http://getcomposer.org/doc/05-repositories.md#package-2

Do note that their example configuration has both dist and source where source is what you need. You will probably also need to configure the autoloading to match that of tcpdf. You can find documentation on that on the composer website as well.

A good thing would also be to send the tcpdf authors an email and ask them if they don't mind adding a composer.json.

Clarence
  • 2,944
  • 18
  • 16