Zend框架2 PDF生成

时间:2013-11-04 18:05:48

标签: zend-framework zend-framework2 pdf-generation

我想要包含24页的单个A5 PDF文档,没有必要考虑slu or或出血,什么是最好的Zendframwork 2 PDF生成模块?你有教程或示例请求给我链接

谢谢..

2 个答案:

答案 0 :(得分:1)

我使用TCPDF

要在Zf2安装中启动并运行,您必须为composer.json添加额外费用。看起来应该是这样的。

{
  "name": "...
  "description": "...",
  "require": {
      "php": ">=5.4",
      ....
      "tecnick.com/tcpdf": ">=6.0.043"
      ....
  },
  "repositories": [{
       "type":"package",
       "package": {
           "name": "tecnick.com/tcpdf",
           "version":"master",
           "source": {
                "url": "http://git.code.sf.net/p/tcpdf/code",
                "type": "git",
                "reference":"master"
           }
       }
  }],
  "minimum-stability": "dev",
  "prefer-stable": true,
  "autoload": {
    "classmap": [
      "vendor/tecnick.com/tcpdf"
    ]
  }
}

此处的"autoload"功能会在您的供应商/编写器路径中的autoload_classmap.php内创建一些条目。

<?php

// autoload_classmap.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
...
   'TCPDF' => $vendorDir . '/tecnick.com/tcpdf/tcpdf.php',
   'TCPDF2DBarcode' => $vendorDir . '/tecnick.com/tcpdf/tcpdf_barcodes_2d.php',
   'TCPDFBarcode' => $vendorDir . '/tecnick.com/tcpdf/tcpdf_barcodes_1d.php',
   'TCPDF_COLORS' => $vendorDir . '/tecnick.com/tcpdf/include/tcpdf_colors.php',
   'TCPDF_FILTERS' => $vendorDir . '/tecnick.com/tcpdf/include/tcpdf_filters.php',
   'TCPDF_FONTS' => $vendorDir . '/tecnick.com/tcpdf/include/tcpdf_fonts.php',
   'TCPDF_FONT_DATA' => $vendorDir . '/tecnick.com/tcpdf/include/tcpdf_font_data.php',
   'TCPDF_IMAGES' => $vendorDir . '/tecnick.com/tcpdf/include/tcpdf_images.php',
   'TCPDF_IMPORT' => $vendorDir . '/tecnick.com/tcpdf/tcpdf_import.php',
   'TCPDF_PARSER' => $vendorDir . '/tecnick.com/tcpdf/tcpdf_parser.php',
   'TCPDF_STATIC' => $vendorDir . '/tecnick.com/tcpdf/include/tcpdf_static.php',
...
);

此时您可以根据自己的喜好创建Pdf对象或使用其他默认类。

//to create a Pdf Object
$pdf = new \TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);

可悲的是,TCPDF网站并不是很好看,也不清楚在那里找到的东西(在我看来)。但它确实提供了相当多的examples

答案 1 :(得分:0)

一切都取决于一些事情;

您需要对PDF进行多少控制 你能安装php扩展吗? 您是从头开始制作PDF还是转换其他格式等

packagist.org上有一些,可以通过作曲家轻松安装,还可以使用ZF2组件:

https://github.com/psliwa/PHPPdf/tree/master