smachara/html2pdfbundle

这是一个用于在Symfony2应用程序中将spipu-Html2pdf的最新版本作为服务的包。我创建这个包是因为'ensepar/html2pdf-bundle'没有使用spipu-Html2pdf和TCPDF的最新版本。其他部分保持不变。

v2.1.1 2021-06-22 01:41 UTC

This package is auto-updated.

Last update: 2024-09-29 20:33:12 UTC


README

这是一个用于在Symfony2应用程序中使用spipu-Html2pdf最新版本的包。

我创建这个包是因为"ensepar/html2pdf-bundle"没有使用spipu-Html2pdf和TCPDF的最新版本。其他部分保持不变。

安装

步骤 1: 设置包和依赖项

composer require smachara/html2pdfbundle

步骤 2: 配置自动加载器

smachara命名空间添加到您的自动加载器

// app/autoload.php
<?php
// ...
$loader->add('smachara',   __DIR__ . '/../vendor');

步骤 3: 在内核中启用包

将包添加到内核中的registerBundles()方法

// app/AppKernel.php
<?php

public function registerBundles()
{
    $bundles = array(
        // ...
        new smachara\html2pdfbundle\smacharaHtml2pdfBundle(),
    );
}

如何使用?

在您的操作中

public function printAction()
    {
        $pdf = $this->get('html2pdf_factory')->create();
        $html = $this->renderView('PdfBundle:Pdf:content.html.twig', array( 'preview' => false));
        $pdf->writeHTML($html);
        $response = new Response($pdf->Output('test.pdf','D'));
        return $response;
    }

您可以将传递给$pdf的任何选项传递过去,例如

$pdf = $this->get('html2pdf_factory')->create('P', 'A4', 'en', true, 'UTF-8', array(10, 15, 10, 15));

如果未提供前一个参数,工厂将使用其默认值。您可以通过将包配置添加到您的app/config/config.yml来更改这些默认值

smachara_html2pdf:
    orientation: P
    format: A4
    lang: en
    unicode: true
    encoding: UTF-8
    margin: [10,15,10,15]

许可证