dongying7847 2013-02-01 16:42
浏览 39
已采纳

在Zend Framework 2中使用ZendPdf

I'm trying to wrap my head around zend framework 2 and it's module system. I have the the skeleton application in the Getting Started guide working. I now want to use ZendPdf to load in an existing pdf file and work with it. I've done the following so far:

  • downloaded and installed ZendPdf using composer to my skeleton app
  • Added ZendPdf to my application_config.php
  • Added a simple controller action to create a new ZendPdf class and load in a document
  • I also created a view for the controller action.

When ever I call the action in the controller I get the following error

Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (ZendPdf) could not be initialized

Obviously, from the error, I need to add zendpdf to the module_config.php so the ModuleManager can pick it up. This is were I get lost. I don't know how to configure zendpdf in the config file. This is what I have so far:

module.config in the Album Module

return array(
'controllers' => array(
    'invokables' => array(
        'Album\Controller\Album' => 'Album\Controller\AlbumController',
    ),
),
// Routes for 
'router' => array(
    'routes' => array(
        'album' => array(
            'type'    => 'segment',
            'options' => array(
                'route'    => '/album[/:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Album\Controller\Album',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),
'view_manager' => array(
    'template_path_stack' => array(
        'album' => __DIR__ . '/../view',
    ),
),
'zendpdf' => array() /* what to do here */
);

This is the controller action in my AlbumController

public function viewPdfAction()
{
  $pdf = ZendPdf::load('/tmp/pdf_report.pdf');
}

This is the application.config

<?php
   return array(
     'modules' => array(
       'Application',
       'Album',
       'AlbumRest',
       'ZendPdf'
     ),
     'module_listener_options' => array(
        'config_glob_paths'    => array(
        'config/autoload/{,*.}{global,local}.php',
     ),
      'module_paths' => array(
          './module',
          './vendor',
     ),
  ),
);

I've been reading the docs but am just not getting it. I need a push in the right direction.

  • 写回答

2条回答 默认 最新

  • douchen4534 2013-02-04 21:55
    关注

    Using clues from Andy this is what I found that worked.

    Install ZendPdf via composer. Using composer will make ZF2 automatically auto-the library. below is the composer.json file that I used

    {
        "repositories": [
          {
            "type": "composer",
            "url": "http://packages.zendframework.com/"
          }
        ],
        "name": "zendframework/skeleton-application",
        "description": "Skeleton Application for ZF2",
        "license": "BSD-3-Clause",
        "keywords": [
            "framework",
            "zf2"
        ],
        "homepage": "http://framework.zend.com/",
        "require": {
            "php": ">=5.3.3",
            "zendframework/zendframework": "2.*",
            "zendframework/zendpdf": "*"
        }
    }
    

    In your controller import the ZendPdf namespace

    use ZendPdf\PdfDocument;
    

    Then somewhere in a Controller action create a new pdf object and work with it

    public funciton someAction()
    {
         $pdf = PdfDocument::load('path/to/pdf');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?