uga / twig2pdf-bundle
twig2pdf
v1.3
2017-02-26 12:44 UTC
Requires
- php: >=5.5
- spipu/html2pdf: ~4.5
- symfony/symfony: >=2.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-24 23:13:09 UTC
README
Twig2pdf Bundle
为Symfony 2/Drupal 8提供一个服务。
_______ _____ ____ _ _ ____ ____ _____ |_ _\ \ / /_ _/ ___| || | | _ \| _ \| ___| | | \ \ /\ / / | | | _| || |_| |_) | | | | |_ | | \ V V / | | |_| |__ _| __/| |_| | _| |_| \_/\_/ |___\____| |_| |_| |____/|_| ____ _ _ _ _ ____ _ _____ ______ __ | __ )| | | | \ | | _ \| | | ____| | __ ) \ / / | _ \| | | | \| | | | | | | _| | _ \\ V / | |_) | |_| | |\ | |_| | |___| |___ | |_) || | |____/ \___/|_| \_|____/|_____|_____| |____/ |_| ____ _ _ _ _ _____ _____ ____ ____ _______ __ | _ \| | / \ | \ | | ____|_ _/ __ \| _ \| ____\ \ / / | |_) | | / _ \ | \| | _| | |/ / _` | | | | _| \ \ / / | __/| |___ / ___ \| |\ | |___ | | | (_| | |_| | |___ \ V / |_| |_____/_/ \_\_| \_|_____| |_|\ \__,_|____/|_____| \_/ \____/
如何安装?
只需将其添加到您的composer.json文件中
"require": { "uga/twig2pdf-bundle": "^1.1" } Or you tape in your ROOT project composer require uga/twig2pdf-bundle
在Kernel中启用它
new UGA\Html2PDFBundle\UGAHtml2PDFBundle() ,
如何制作它?
在您的控制器中
protected $pdf2html ; public function __construct( \UGA\Html2PDFBundle\Factory\Html2pdfFactory $pdf2html ) { $this->pdf2html = $pdf2html ; }
在您的操作中
$html2pdf = $this->pdf2html->getInstance() ; $html2pdf->WriteHTML($template); $html2pdf->Output('exemple.pdf');
您可以传递您想要传递给twig2pdf的每个选项,例如
$html2pdf = $this->pdf2html->getInstance('P', 'A4', 'en', true, 'UTF-8', array(10, 15, 10, 15)); or by container
$html2pdf = $this->container->get('uga_html2_pdf.service')->getInstance('P', 'A4', 'fr', null, null, null);
如果未提供前面的参数,工厂将使用其默认值。您可以通过向您的app/config/config.yml
中添加包配置来更改这些默认值
uga_html2_pdf: html2_pdf_orientation: 'P' html2_pdf_format: 'A4' html2_pdf_lang: 'fr' html2_pdf_unicode: true html2_pdf_encoding: 'UTF-8' html2_pdf_margin: [10,15,10,15]
与twig模板集成
$template = $this->template->render('AcmeMyAppBundle:Default:index.html.twig',array( 'CLASS_HTML2PDF' => "HTML2PDF FOR SYMFONY 2.8.18 " )) ; $html2pdf = $this->pdf2html->getInstance() ; $html2pdf->WriteHTML($template); $html2pdf->Output('exemple.pdf');
完整示例(控制器)
<?php namespace Acme\MyAppBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DefaultController extends Controller { protected $entityManager ; protected $template ; protected $pdf2html ; public function __construct( \Doctrine\ORM\EntityManager $entityManager , \Twig_Environment $template , \UGA\Html2PDFBundle\Factory\Html2pdfFactory $pdf2html ) { $this->entityManager = $entityManager; $this->template = $template ; $this->pdf2html = $pdf2html ; } public function indexAction() { $template = $this->template->render('AcmeMyAppBundle:Default:index.html.twig',array( 'CLASS_HTML2PDF' => "CLASS HTML2PDF FOR SYMFONY 2.8.18 " )) ; $html2pdf = $this->pdf2html->getInstance() ; $html2pdf->WriteHTML($template); $html2pdf->Output('exemple.pdf'); return $this->render('AcmeMyAppBundle:Default:index.html.twig'); } }
在供应商项目中更新包?
composer install
信息
- 程序员:Spipu
- 网站: http://html2pdf.fr/
- Wiki: http://html2pdf.fr/en/wiki
- 支持: http://html2pdf.fr/en/forum
联系我
Nadir Fouka < nadir@fouka.ovh >
- 格勒诺布尔阿尔卑斯大学2017年网络开发者
- 数据科学家Planet@Dev