如何将TCPDF安装到symfony 2.7

时间:2015-06-16 04:37:03

标签: symfony tcpdf

我想通过symfony 2生成PDF文件,所以我使用

  

作曲家需要tecnick.com/tcpdf

它在我的Vendors文件夹中创建了新文件夹名tecnick.com/tcpdf 那么我如何调用tcpdf类?

2 个答案:

答案 0 :(得分:2)

此捆绑包使用official website中的最新版本的TCPDF。作为Symfony软件包的安装是不同的(来自常规安装),因为您将它与Symfony框架一起使用。在这种情况下,您将不会使用require_once等,因为Symfony会为您执行此操作。

有关一般信息,请考虑reading the official bundle documentation

首先将其添加到项目require

composer.json部分
"whiteoctober/tcpdf-bundle": "dev-master"

然后执行composer install

完成后,在app/AppKernel.php

中注册该捆绑包
<?php

 public function registerBundles()
 {
     $bundles = array(
      // ...
         new WhiteOctober\TCPDFBundle\WhiteOctoberTCPDFBundle(),
      );
 }

现在您可以在控制器上使用TCPDF,例如:

class MyController extends Controller {
    ...

    public function mypdfAction(Request $request){

        $pdf = $this->container->get("white_october.tcpdf")->create(
            'LANDSCAPE',
            PDF_UNIT,
            PDF_PAGE_FORMAT,
            true,
            'UTF-8',
            false
        );
        $pdf->SetAuthor('qweqwe');
        $pdf->SetTitle('Prueba TCPDF');
        $pdf->SetSubject('Your client');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
        $pdf->setFontSubsetting(true);

        $pdf->SetFont('helvetica', '', 11, '', true);
        $pdf->AddPage();

        $html = '<h1>Working on Symfony</h1>';

        $pdf->writeHTMLCell(
            $w = 0,
            $h = 0,
            $x = '',
            $y = '',
            $html,
            $border = 0,
            $ln = 1,
            $fill = 0,
            $reseth = true,
            $align = '',
            $autopadding = true
        );

        $pdf->Output("example.pdf", 'I');
    }
}

答案 1 :(得分:0)

有可用的文档:TCPDF