定制 takeoo/zend-pdf 二次开发

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

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

takeoo/zend-pdf

Composer 安装命令:

composer require takeoo/zend-pdf

包简介

Create pdf from view in zend framework 2

README 文档

README

Create pdf from view in ZendFramework 3

Works on zend framework v3.*

IF you want to use it with older versions, use one of previous tags

Requirements

  • wkhtmltopdf installed on your server

    • Debian, Ubuntu:
    sudo apt-get install wkhtmltopdf
    • *Debian servers have known errors with wkhtmltopdf lib, so if you get error like:
    wkhtmltopdf: cannot connect to X server

    install xvfb:

    sudo apt-get install xvfb
  • zend-view 2.3* is installed as dependency

  • zend-service-manager is already installed with 3.* version of zf3.

Install

  • Composer install

     composer require takeoo/zend-pdf
  • Add "Takeoo\Pdf" to 'modules' array in application.config.php

Usage

  • Takeoo\Zend-pdf will create service throughout service manager, so it is available in serviceLocator as 'PdfCreator';

  • Instantiate:

$pdfCreator = $serviceManager->get('PdfCreator');

NOTE: PdfCreator is not shared service, so every call to serviceManager will create new instance.

PdfCreator uses ViewResolver which is auto-magically injected to PhpRenderer if have MVC application, so you can use any view or layout you have in your app!

  • Set layout

     $pdfCreator->setLayoutTemplate('layout/pdf-template');
    • Add view as you would in your response, just pass name and variables to createHtml() function
    $pdfCreator->createHtml('path/to/view', ['variableName' => $variableValue]);

    OR you can directly pass already created view model

    $pdfCreator->createHtmlFromViewModel($viewModel);
  • Output

    • All modern browser support pdf output directly to browser:

      $pdfCreator->output();
    • get file handle

      $pdfCreator->writePdf();

    NOTE: Both above functions will save file to your disk

  • Get file path

    $pdfCreator->getFilePath();
  • By default all files are generated to your project root into "{Ymd_His}.pdf"

  • Change file destination

    $pdfCreator->setPdfFileName('path/to/desired/folder/nameofyourfile.pdf');

NOTE: All functions with public scope (with exception of output() and writePdf()) are fluent, so you can chain all functions:

$pdfCreator->setLayoutTemplate('layout/pdf-layout')
  ->createHtml('view', ['variable1' => $variable1Value])
  ->setPdfFileName('./../file.pdf')
  ->setHasXvfb(false)
  ->output();

NOTE: By default all wkhtmltopdf conversions are created with setHasXvfb(true), so you have to have installed Xvfb on your server! If you want to turn it of just do:

$pdfCreator->setHasXvfb(false);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-03-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固