mPDF Manual – mPDF functions

setSourceFile() (since 8.0)

(mPDF ≥ 8.0)

setSourceFile – Specify the source PDF file used to import pages into the document

Description

int setSourceFile ( string|resource|\setasign\Fpdi\PdfParser\Streamreader $file )

Specify the source PDF file used to import pages into the document.

Parameters

$file

This parameter specifies the source PDF file used to import pages into the document. It can either be a path to a file, file resource handle, or a FPDI StreamReader instance with contents of the file.

Note:  If path to a file, $file should be a relative path to a local file.

Return Value

setSourceFile() returns the number of pages in the source file.

Changelog

Version Description
8.0 Function was added.

Examples

Example #1

<?php

// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();

// Specify a PDF template
$pagecount = $mpdf->setSourceFile('logoheader.pdf');

// Import the last page of the source PDF file
$tplId = $mpdf->importPage($pagecount);
$mpdf->UseTemplate($tplId);

$mpdf->WriteHTML('Hello World');
$mpdf->Output();

See Also

Fork me on GitHub