dompdf与Symfony 2.1项目

dompdf与Symfony 2.1项目,symfony,symfony-2.1,dompdf,Symfony,Symfony 2.1,Dompdf,如何使dompdf与Symfony 2.1项目一起工作? 我遵循了这一点,但我仍然得到了这个例外: 注意:使用未定义的常量dompd_LIB_DIR-假定 中的“DOMPDF_LIB_DIR” [blabla]/vendor/dino/dompdf/lib/dompdf/stylesheet.cls.php 第16行 如果不是这样,使用Symfony 2.1从html创建pdf的最佳和最简单的库是什么?您还需要包含dompdf\u config.inc.php文件。您还需要包含dompdf\u

如何使dompdf与Symfony 2.1项目一起工作? 我遵循了这一点,但我仍然得到了这个例外:

注意:使用未定义的常量dompd_LIB_DIR-假定 中的“DOMPDF_LIB_DIR” [blabla]/vendor/dino/dompdf/lib/dompdf/stylesheet.cls.php 第16行


如果不是这样,使用Symfony 2.1从html创建pdf的最佳和最简单的库是什么?

您还需要包含
dompdf\u config.inc.php
文件。

您还需要包含
dompdf\u config.inc.php
文件。

以下是我在Symfony2项目中为使dompdf可用所做的工作:

  • 需要DinoPDF composer软件包: php composer.phar需要0.1.1版的dino/dompdf(或dev master)

  • 加载过程中的某个位置需要使用DomPDF init文件()

    • 将vendor/dino/dompdf/dompdf_config.inc.php.dist复制到app/dompdf_config.inc.php
    • 将vendor/dino/dompdf/dompdf_config.custom.inc.php.dist复制到app/dompdf_config.custom.inc.php
    • 在应用程序/autoload.php中添加:

      require_once __DIR__.'/dompdf_config.inc.php';
      
  • dompdf_config.inc.php定义了dompdf安装的路径。DinoPDF发行版更改了库中的路径,因此必须注意:

    DOMPDF\u INC\u DIR:主要的DOMPDF类。在DOMPdf的dinoPDF发行版中,此文件夹从DOMPdf/include重命名为DOMPdf/lib/DOMPdf

    DOMPDF_LIB_DIR:附加资源-字体等。在DOMPDF的dinoPDF发行版中,此文件夹从DOMPDF/LIB重命名为DOMPDF/LIB/vendor

    以下是我对dompdf_config.inc.php所做的更改:

    /**
     * The root of your DOMPDF installation
     */
    define("DOMPDF_DIR", str_replace(DIRECTORY_SEPARATOR, '/',                     realpath(__DIR__.'/../vendor/dino/dompdf/')));
    /**
     * The location of the DOMPDF include directory
     * Main DOMPdf classes
     * In dinoPDF distribution of DOMPdf this folder is renamed from dompdf/include to     dompdf/lib/DOMPDF
     */
    define("DOMPDF_INC_DIR", DOMPDF_DIR . "/lib/DOMPDF");
    
    /**
     * The location of the DOMPDF lib directory
     * Additional resources - fonts, etc.
     * In dinoPDF distribution of DOMPdf this folder is renamed from dompdf/lib to     dompdf/lib/vendor
     */
    define("DOMPDF_LIB_DIR", DOMPDF_DIR . "/lib/vendor");
    
    /** Include the custom config file if it exists */
    if ( file_exists(__DIR__ . "/dompdf_config.custom.inc.php") ){
        require_once(__DIR__ . "/dompdf_config.custom.inc.php");
    }
    
    def("DOMPDF_FONT_DIR", DOMPDF_LIB_DIR . "/fonts/");
    
    这应该正确地包括库,以便可以在控制器中使用,例如:

    /**
     * @Route("/export_pdf", name="export_pdf")
     */
    public function exportPDFAction($id)
    {   
        $html =
        '<html><body>'.
        '<p>Put your html here, or generate it with your favourite '.
        'templating system.</p>'.
        '</body></html>';
    
        $dompdf = new \DOMPDF();
        $dompdf->load_html($html);
        $dompdf->render();
    
        $response = new Response();
    
        $response->setContent($dompdf->output());
        $response->setStatusCode(200);
        $response->headers->set('Content-Type', 'application/pdf');
    
        return $response;
    }
    
    /**
    *@Route(“/export\u pdf”,name=“export\u pdf”)
    */
    公共函数导出参数($id)
    {   
    $html=
    ''.
    “将你的html放在这里,或者用你最喜欢的内容生成它”。
    “模板系统。

    ”。 ''; $dompdf=new\dompdf(); $dompdf->load_html($html); $dompdf->render(); $response=新响应(); $response->setContent($dompd->output()); $response->setStatusCode(200); $response->headers->set('Content-Type','application/pdf'); 返回$response; }
    以下是我为在Symfony2项目中使用DOMPDF所做的工作:

  • 需要DinoPDF composer软件包: php composer.phar需要0.1.1版的dino/dompdf(或dev master)

  • 加载过程中的某个位置需要使用DomPDF init文件()

    • 将vendor/dino/dompdf/dompdf_config.inc.php.dist复制到app/dompdf_config.inc.php
    • 将vendor/dino/dompdf/dompdf_config.custom.inc.php.dist复制到app/dompdf_config.custom.inc.php
    • 在应用程序/autoload.php中添加:

      require_once __DIR__.'/dompdf_config.inc.php';
      
  • dompdf_config.inc.php定义了dompdf安装的路径。DinoPDF发行版更改了库中的路径,因此必须注意:

    DOMPDF\u INC\u DIR:主要的DOMPDF类。在DOMPdf的dinoPDF发行版中,此文件夹从DOMPdf/include重命名为DOMPdf/lib/DOMPdf

    DOMPDF_LIB_DIR:附加资源-字体等。在DOMPDF的dinoPDF发行版中,此文件夹从DOMPDF/LIB重命名为DOMPDF/LIB/vendor

    以下是我对dompdf_config.inc.php所做的更改:

    /**
     * The root of your DOMPDF installation
     */
    define("DOMPDF_DIR", str_replace(DIRECTORY_SEPARATOR, '/',                     realpath(__DIR__.'/../vendor/dino/dompdf/')));
    /**
     * The location of the DOMPDF include directory
     * Main DOMPdf classes
     * In dinoPDF distribution of DOMPdf this folder is renamed from dompdf/include to     dompdf/lib/DOMPDF
     */
    define("DOMPDF_INC_DIR", DOMPDF_DIR . "/lib/DOMPDF");
    
    /**
     * The location of the DOMPDF lib directory
     * Additional resources - fonts, etc.
     * In dinoPDF distribution of DOMPdf this folder is renamed from dompdf/lib to     dompdf/lib/vendor
     */
    define("DOMPDF_LIB_DIR", DOMPDF_DIR . "/lib/vendor");
    
    /** Include the custom config file if it exists */
    if ( file_exists(__DIR__ . "/dompdf_config.custom.inc.php") ){
        require_once(__DIR__ . "/dompdf_config.custom.inc.php");
    }
    
    def("DOMPDF_FONT_DIR", DOMPDF_LIB_DIR . "/fonts/");
    
    这应该正确地包括库,以便可以在控制器中使用,例如:

    /**
     * @Route("/export_pdf", name="export_pdf")
     */
    public function exportPDFAction($id)
    {   
        $html =
        '<html><body>'.
        '<p>Put your html here, or generate it with your favourite '.
        'templating system.</p>'.
        '</body></html>';
    
        $dompdf = new \DOMPDF();
        $dompdf->load_html($html);
        $dompdf->render();
    
        $response = new Response();
    
        $response->setContent($dompdf->output());
        $response->setStatusCode(200);
        $response->headers->set('Content-Type', 'application/pdf');
    
        return $response;
    }
    
    /**
    *@Route(“/export\u pdf”,name=“export\u pdf”)
    */
    公共函数导出参数($id)
    {   
    $html=
    ''.
    “将你的html放在这里,或者用你最喜欢的内容生成它”。
    “模板系统。

    ”。 ''; $dompdf=new\dompdf(); $dompdf->load_html($html); $dompdf->render(); $response=新响应(); $response->setContent($dompd->output()); $response->setStatusCode(200); $response->headers->set('Content-Type','application/pdf'); 返回$response; }
    还有其他选项,例如:

    -一个基于WebKit引擎的控制台html2pdf转换工具,可确保符合标准


    -集成Symfony2和wkhtmltopdf的捆绑包

    还有其他选项,例如:

    -一个基于WebKit引擎的控制台html2pdf转换工具,可确保符合标准


    -将Symfony2与wkhtmltopdf集成的捆绑包有一种更简单的方法,因为dompdf本身现在具有基本的编写器支持:


    很抱歉没有在这里内联发布这些步骤,但我已经在不久前写了这篇博文

    有一种简单得多的方法,因为DOMPF本身现在拥有基本的作曲家支持:


    很抱歉没有在这里内联发布这些步骤,但我已经在不久前写了这篇博文

    在Symfony2项目中包含DomPDF实际上有一种更简单的方法

    首先,在
    composer.json
    文件中添加DomPDF:

    {   
        "require": {
            // ...
            "dompdf/dompdf": "dev-master"
        }
    }
    
    安装后,编辑Symfony应用程序的
    app/autoload.php
    文件,并在末尾添加以下行(在
    return
    语句之前):

    你完了


    但是正如Slavik上面提到的,可能有更好的dompdf解决方案,比如使用
    wkhtmltopdf
    的KnpSnappyBundle,实际上有一种更简单的方法可以将dompdf包含在Symfony2项目中

    首先,在
    composer.json
    文件中添加DomPDF:

    {   
        "require": {
            // ...
            "dompdf/dompdf": "dev-master"
        }
    }
    
    安装后,编辑Symfony应用程序的
    app/autoload.php
    文件,并在末尾添加以下行(在
    return
    语句之前):

    你完了


    但正如Slavik上面提到的,dompdf可能有更好的解决方案,比如使用
    wkhtmltopdf

    的KNPNAPybundle,我不理解第5行:“复制dompdf_config.*.inc.php.dist