PHP code example of francerz / exfpdf

1. Go to this page and download the library: Download francerz/exfpdf library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

francerz / exfpdf example snippets


OutputPsr7(
  \Psr\Http\Message\ResponseFactoryInterface $responseFactory,
  \Psr\Http\Messsage\StreamFactoryInterface $streamFactory,
  string $filename,
  bool $inline = true,
  bool $isUTF8 = false
)

$pdf = new ExFPDF();
// ... create PDF

// ... load HTTP Factories
$responseFactory = new ResponseFactory(); // from a PSR-17 compliant library
$streamFactory = new StreamFactory(); // from a PSR-17 compliant library

// Output PSR-7 file
$response = $pdf->OutputPsr7($responseFactory, $streamFactory, 'my-file.pdf');

OutputPsr7WithManager(
  \Francerz\Http\Utils\HttpFactoryManager $hfm,
  string $filename,
  bool $inline = true,
  bool $isUTF8 = false
)

$pdf = new ExFPDF();
// ... create PDF

// Output PSR-7 Response object
$factories = new HttpFactoryManager(new ResponseFactory(), new StreamFactory());
$response = $pdf->OutputPsr7WithManager($factories, 'my-file.pdf');

$pdf = new ExFPDF();
// ... create PDF

// Output PSR-7 Response object
$response = $pdf->OutputPsr7WithManager(HttpFactory::getManager(), 'my-file.pdf');

// Sets Y position at 25% (one quarter) from page top.
$pdf->SetY('25%');
// Sets X position at 25% (one quarter) from page left.
$pdf->SetX('25%');

// Draws a cell with 50% width and height of current page size.
$pdf->Cell('50%','50%', '', 1);

// Sets Y position at top margin.
$pdf->SetY('~0');
// Sets X position at left margin.
$pdf->SetX('~0');

// Draws a cell with 25% width and 10% height of current page content.
$pdf->Cell('~25%', '~10%', '', 1);

// translates pointer 10 units right to current X.
$pdf->OffsetX(10);

// translates pointer 20 units bottom to current Y.
$pdf->OffsetY(20);

// translates equivalent to two previous in a single line.
$pdf->OffsetXY(10, 20);

// offset may be negative and relative units
$pdf->OffsetXY(-10, '~10%');

MoveToPin($pinName, $axis = 'XY', $offset = 0, $offsetY = 0);

// Defines a coordinate pin at current X,Y with name 'start'.
$pdf->SetPin('start');

// Retrieves 'start' pin positions.
$x = $pdf->GetPinX('start');
$y = $pdf->GetPinY('start');

// Moves pdf position back to pin 'start'
$pdf->MoveToPin('start');

// Moves pdf X position back to pin 'start'
$pdf->MoveToPin('start','X');

// Moves pdf Y position back to pin 'start'
$pdf->MoveToPin('start','Y');

// Moves pdf X position back to pin 'start' and adds 10 units.
$pdf->MoveToPin('start', 'X', 10);

// Moves pdf Y position back to pin 'start' and adds 20 units.
$pdf->MoveToPin('start', 'Y', 20);

// Moves pdf position back to pin 'start' and adds X: 10 units, Y: 20 units.
$pdf->MoveToPin('start', 'XY', 10, 20);

SetLineHeight(float $size)

$pdf->SetFontSize(10);
$pdf->SetLineHeight(1.1); // 110% of actual size (11pt)

$pdf->Cell('100%', null, 'This text is size 10pt, but Cell is 11pt height with LineHeight 1.1');

SetSourceEncoding(string $encoding)

$pdf->SetSourceEncoding('UTF-8');
$pdf->Cell('100%', null, 'Benjamín pidió una bebida de kiwi y fresa; Noé, sin vergüenza, la más exquisita champaña del menú.');

CellRight($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='', $margin=0)

$pdf->CellRight(15, 5, 'Date: ', 0, 0, 'R', false, '', 30);
$pdf->CellRight(30, 5, date('Y-m-d'), 1, 1, 'C', false, '', 0);

$userName = "My Name";

$pdf = new ExFPDF();
$pdf->AliasNbPages();
$pdf->SetFont('Arial', '', 12);
$pdf->SetHeader(function(ExFPDF $exfpdf) use ($userName) {
    $exfpdf->Cell('~100%', 10, "Hello {$userName}", 1);
});
$pdf->SetFooter(function(ExFPDF $exfpdf) {
    $exfpdf->Cell('~100%', 10, 'Page '.$exfpdf->PageNo(), 1, 0, 'R');
});
$pdf->AddPage();

$pdf->Output('I');

$pdf = new ExFPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 12);

// Creates table with three columns with given widths
$table = $pdf->CreateTable(['~25%','~60%','~15%']);

// Sets Line Height as its used to extend cell size.
$pdf->SetLineHeight(1.2);

// Set header styling
$pdf->SetFont('','B', 14);
$pdf->SetFillColor('#CA4A0F');
$pdf->SetTextColor('#FFF');

// Creates a row with heading
$row = $table->AddRow();
$row->Cell('Price', $align='C', $fill=true, $colspan=1, $rowspan=2);  // 2 rows tall
$row->Cell('Product', $align='C', $fill=true, $colspan=2);            // 2 colums wide
$row = $table->AddRow();
$row->CellSpan($fill=true); // $rowspan still not supported this is placeholder
$row->Cell('Description', $align='C', $fill=true);
$row->Cell('Quantity', $align='C', $fill=true);

// Creates content rows
$pdf->SetFont('', '', 12);
$pdf->SetTextColor('#000');

$row = $table->AddRow();
$row->Cell('$ 340.00', $align='R');
$row->Cell('Gymbal');
$row->Cell('3', 'C');
$row = $table->AddRow();
$row->Cell('$ 970.00', $align='R');
$row->Cell('Laptop');
$row->Cell('1', 'C');
$row = $table->AddRow();
$row->Cell('$ 120.00', $align='R');
$row->Cell('Headphones');
$row->Cell('2', 'C');

// Draws all borders in table
$table->DrawBorders();

$pdf->barcode128(string $code, $w, $h, $x = '0+', $y = '0+');

$pdf->barcode39(string $code, $w, $h, $x, $y);

$pdf->QrCode(string $data, $size, $level = 'H');
$pdf->DataMatrix(string $data, $size);

$matrix = $pdf->GetQrCodeMatrix(string $data, $level = 'H');
$pdf->DrawBinaryMatrix($matrix, $size);

$matrix = $pdf->GetDataMatrixMatrix(string $data);
$pdf->DrawBinaryMatrix($matrix, $size);