arimac/fpdf

FPDF is a PHP class which allows to generate PDF files with pure PHP. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.

1.8.5 2021-12-30 21:45 UTC

This package is not auto-updated.

Last update: 2024-05-04 06:32:53 UTC


README

This is a fork of official mirror of the FPDF library. We changed it to support streaming chunked data. You can avoid memory exceed errors by using this library.

Official FPDF Documentation

Installation with Composer

If you're using Composer to manage dependencies, you can use

$ composer require arimac/fpdf:^1.8

or you can include the following in your composer.json file:

{
    "require": {
        "arimac/fpdf": "^1.8"
    }
}

Usage

  • To download a file as a stream
<?php
require('fpdf.php');

$pdf = new FPDF();
$pdf->StartDownload('sales_report.pdf');
for($i=0; $i<100000; $i++) {
  $pdf->AddPage();
  $pdf->SetFont('Arial','B',16);
  $pdf->Cell(40,10,'Hello World!');
}
$pdf->Close();

Now FPDF will sending the generated data to the browser without waiting to finish the loop.

  • To present a preview of a file as stream
require('fpdf.php');

$pdf = new FPDF();
$pdf->StartPreview('sales_report.pdf');
for($i=0; $i<100000; $i++) {
  $pdf->AddPage();
  $pdf->SetFont('Arial','B',16);
  $pdf->Cell(40,10,'Hello World!');
}
$pdf->Close();

Same as above method. But it opening the generated PDF file insteed of downloading.

  • To directly write to a file
require('fpdf.php');

$pdf = new FPDF();
$pdf->StartFile('sales_report.pdf');
for($i=0; $i<100000; $i++) {
  $pdf->AddPage();
  $pdf->SetFont('Arial','B',16);
  $pdf->Cell(40,10,'Hello World!');
}
$pdf->Close();