定制 littlerocket/pdf-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

littlerocket/pdf-bundle

Composer 安装命令:

composer require littlerocket/pdf-bundle

包简介

This bundle integrates Symfony with PHPPdf library. Fork to fix the bundle for usage with PHP7

关键字:

README 文档

README

This bundle integrates Symfony2 with PHPPdf library. Thanks to this bundle you can easily generate PDF or image (png, jpg) files.

Documentation of PHPPdf you can find on github (README file).

Installation

  1. Use composer. PsPdfBundle requires "minimum-stability" equals to dev. Run this command:

    composer require littlerocket/pdf-bundle

  2. Register bundle in AppKernel:

     //app/AppKernel.php
     public function registerBundles()
     {
         return array(
             // ..
             new Ps\PdfBundle\PsPdfBundle(),
             // ..
         );
     }
    

Configuration

All options are optional.

# app/config/config.yml
ps_pdf:
    nodes_file: ~
    fonts_file: ~
    complex_attributes_file: ~
    colors_file: ~
    use_cache_in_stylesheet: ~
    cache:
      type: ~
      options: ~
    markdown_stylesheet_filepath: ~
    markdown_document_template_filepath: ~
    document_parser_type: ~
  • nodes_file - path to file with nodes/tags definitions, internal nodes.xml file from PHPPdf library is used by default
  • fonts_file - path to file with fonts definitions, internal fonts.xml file from PHPPdf library is used by default
  • complex_attributes_file - path to file with complex attributes definitions, internal complex-attributes.xml file from PHPPdf library is used by default
  • colors_file - path to file with default palette of colors, internal colors.xml file from PHPPdf library is used by default
  • cache.type - type of cache, supported are all backend cache from Zend_Cache component (for instance File, Apc, Memcached, Sqlite etc.). File engine is used by default.
  • cache.options - specyfic options for cache engine (for instance "cache_dir" for File engine). cache_dir by default is as same as kernel.cache_dir.
  • use_cache_in_stylesheet - stylesheet maching rules will be cache, if this option is set. In complex stylesheet cache significantly improves performance. Default is true, but in dev environment cache should be off.
  • markdown_stylesheet_filepath - filepath of stylesheet for markdown parser
  • markdown_document_template_filepath - xml document template form output of markdown parser
  • document_parser_type - default parser type: xml or markdown

Images in source document

If you want to display image, you must provide absolute path to image file via "src" attribute of image tag. Asset Twig function dosn't work, because it converts image path to relative path according to web directory. To make using of images easier, bundle provides Twig function, that converts image logical name to real, absolute path.

Example:

<pdf>
    <dynamic-page>
        <!-- pdf_image('BundleName:image-name.extension') -->
        <img src="{{ pdf_image('SymfonyWebConfiguratorBundle:blue-arrow.png') }}" />
    </dynamic-page>
</pdf>

Bundle based paths in fonts and document xml file

If you want to use custom fonts, you should create your own fonts.xml config file (default fonts filepath is PHPPdf\Resources\config\fonts.xml). To make easier defining fonts paths, bundle based paths are supported. Example:

<!-- some fonts.xml file -->
<italic src="%SomeBundle:file.ttf%" /> 

"%SomeBundle:file.ttf%" will be replaced by "path/to/SomeBundle/Resources/file.ttf"

Example

// In controller
//...
use Ps\PdfBundle\Annotation\Pdf;
//...

/**
 * @Pdf()
 */
public function helloAction($name)
{
    $format = $this->get('request')->get('_format');
    
    return $this->render(sprintf('SomeBundle:SomeController:helloAction.%s.twig', $format), array(
        'name' => $name,
    ));
}

// in helloAction.html.twig
Hello {{ name }}!

// in helloAction.pdf.twig
<pdf>
    <dynamic-page>
        Hello {{ name }}!
    </dynamic-page>
</pdf>

Bundle automatically detects pdf format (via _format) request and create pdf document from response.

Pdf annotation has four optional properties:

  • headers - associative array of specyfic headers
  • stylesheet - pdf stylesheet template file in standard Symfony2 notation ("Bundle:Controller:file.format.engine")
  • documentParserType - type of parser: xml or markdown
  • enableCache - pdf output should by cached? True or false, default: false. Hash (md5) from template and stylesheet content is a cache key, only PHPPdf invocation is cached, controller is always called.

littlerocket/pdf-bundle 适用场景与选型建议

littlerocket/pdf-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.03k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 08 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 44
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-23