Zend framework 2 PDF generation [closed]

南楼画角 提交于 2020-01-03 06:30:12

问题


I want to crate single A5 PDF document with 24 pages , There is no need to account for slugs or bleed , What is the Best Zendframwork 2 PDF generation Module for this ? Do you have tutorials or example pleas send me the links

thank you ..


回答1:


I use TCPDF.

To get it up and running within your Zf2 installation you have to add a litle extra to your composer.json. It should look something like this.

{
  "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"
    ]
  }
}

The "autoload" functionality here will create a few entries within your autoload_classmap.php in your vendor/composer path.

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

At this point you can just create a Pdf Object or use the other defiened Classes to your liking.

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

Sadly the TCPDF website is not quite the looker nor is it clear to find things there (in my opinion). But it does provide quite a few examples which cover quite a bit.




回答2:


that all depends on a few things;

how much control you need over the PDF Are you able to install php extensions? Are you making the PDF from scratch, or converting other formats etc

There's some on packagist.org, which are easily installable via composer, and one which will work with ZF2 components:

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


来源:https://stackoverflow.com/questions/19774157/zend-framework-2-pdf-generation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!