uga/twig2pdf-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

uga/twig2pdf-bundle

Composer 安装命令:

composer require uga/twig2pdf-bundle

包简介

twig2pdf

README 文档

README


Twig2pdf Bundle

Scrutinizer Code Quality Minimum PHP Version License Build Status

Twig2pdf for Symfony 2/Drupal 8 as a service.

 _______        _____ ____ _  _   ____  ____  _____ 
|_   _\ \      / /_ _/ ___| || | |  _ \|  _ \|  ___|
  | |  \ \ /\ / / | | |  _| || |_| |_) | | | | |_   
  | |   \ V  V /  | | |_| |__   _|  __/| |_| |  _|  
  |_|    \_/\_/  |___\____|  |_| |_|   |____/|_|    
                                                    
 ____  _   _ _   _ ____  _     _____   ______   __
| __ )| | | | \ | |  _ \| |   | ____| | __ ) \ / /
|  _ \| | | |  \| | | | | |   |  _|   |  _ \\ V / 
| |_) | |_| | |\  | |_| | |___| |___  | |_) || |  
|____/ \___/|_| \_|____/|_____|_____| |____/ |_|  
                                                  
 ____  _        _    _   _ _____ _____ ____  ____  _______     __
|  _ \| |      / \  | \ | | ____|_   _/ __ \|  _ \| ____\ \   / /
| |_) | |     / _ \ |  \| |  _|   | |/ / _` | | | |  _|  \ \ / / 
|  __/| |___ / ___ \| |\  | |___  | | | (_| | |_| | |___  \ V /  
|_|   |_____/_/   \_\_| \_|_____| |_|\ \__,_|____/|_____|  \_/   
                                      \____/                     

How to install ?

Just add this to your composer.json file:

"require": {
  "uga/twig2pdf-bundle": "^1.1"
}

Or you tape in your ROOT project 
composer require uga/twig2pdf-bundle

Enable it in the Kernel

new UGA\Html2PDFBundle\UGAHtml2PDFBundle() , 

How to make it ?

In your controller:

    protected $pdf2html  ; 

    public function __construct(
                \UGA\Html2PDFBundle\Factory\Html2pdfFactory $pdf2html 
            )
    {
        $this->pdf2html         = $pdf2html ; 
    }

In your action:

    $html2pdf =  $this->pdf2html->getInstance() ;
    $html2pdf->WriteHTML($template);
    $html2pdf->Output('exemple.pdf');

You can pass every option you would pass to twig2pdf, for instance :

$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);

If the previous arguments are not provided, the factory uses its own default values. You can change this default values by adding the bundle configuration to your 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]

Integration with twig template :

    $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');

Full example ( Controller ) :

    <?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');
    }
}

Update package in vendor project ?

composer install

Information:

Contact Me

Nadir Fouka < nadir@fouka.ovh >

  • Web Developer Grenoble Alpes University 2017
  • Data Scientist Planet@Dev

uga/twig2pdf-bundle 适用场景与选型建议

uga/twig2pdf-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 272.49k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 02 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「pdf」 「TCPDF」 「html2pdf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 uga/twig2pdf-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 uga/twig2pdf-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 uga/twig2pdf-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 272.49k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-24