2015-06-16 23 views
1

我想通過symfony的2 generata PDF文件,所以我用如何安裝TCPDF到Symfony的2.7

作曲家需要tecnick.com/tcpdf

它創建新的文件夾名稱tecnick.com/ tcpdf在我的供應商文件夾 那麼我怎麼稱呼tcpdf類?

+0

看網上單證 – Blip

+0

我請參閱http:/ /symfony.com/doc/current/cookbook/bundles/installation.html但tecnick不會創建捆綁 –

回答

0

有這個可用文檔:TCPDF

+0

但我想使用tecnick –

2

這個捆綁使用TCPDF從official website的最後一個版本。 Symfony包的安裝與常規安裝不同,因爲您將它與Symfony框架結合使用。在這種情況下,你不會使用require_once等,因爲Symfony爲你做到了這一點。

對於一般信息,可以考慮reading the official bundle documentation

首先將其添加到您的項目composer.json

"whiteoctober/tcpdf-bundle": "dev-master" 

require部分然後執行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'); 
    } 
}