ftwex/fpdf-symfony2

fpdf 为 symfony2 设计的供应商,基于 royopa/fpdf-symfony2

1.0 2015-07-17 01:36 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:36:48 UTC


README

使用 FPDF 1.7,在 Symfony 2.5+ 上测试过

Build Status Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality

安装和使用

该包在 Composer 上可用。

如果您使用 Composer 管理依赖项,可以使用

composer require ftwex/fpdf-symfony2

使用方法

class WelcomeController extends Controller
{
    public function indexAction()
    {
        $pdf  = new \FPDF_FPDF();
        $pdi  = new \FPDF_FPDI();

        $pdf->AddPage();
        $pdf->SetFont('Arial','B',16);
        $pdf->Cell(40,10,'Hello World!');
        $pdf->Output();
    }
}

FPDF

FPDF 是一个 PHP 类,允许使用纯 PHP 生成 PDF 文件,也就是说,不使用 PDFlib 库。FPDF 是一个开源项目:您可以用于任何类型的用途,并修改它以适应您的需求。

在 fpdf 主页上,您可以找到文档、论坛等的链接。

示例

查看我的控制器

<?php

namespace Acme\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

class WelcomeController extends Controller
{
    public function indexAction()
    {
        $pdf  = new \FPDF_FPDF();
        $pdi  = new \FPDF_FPDI();

        //my code...

        return new Response($pdf->Output( 'MyPDF.pdf', 'I'), 200, array('Content-Type' => 'application/pdf'));
    }
}