SetDocTemplate()
(mPDF ≥ 2.3)
SetDocTemplate – Specify an external PDF file to use as a template
Description
void SetDocTemplate ( [ string $file [, boolean $continue ]])
Specify an external PDF file to use as a template. Each page of the external source PDF file will be used as a template for the corresponding page in your new document. If the current mPDF document has more pages than the external PDF source document, the last page or last 2 pages will (optionally) continue to be used for any remaining pages.
Parameters
- $file
-
This parameter specifies the source PDF file used as the template document. $file should be a relative path to a local file.
Default: BLANK
- $continue
-
Values:
1
|0
|true
|false
If
true
(or any positive value) it forces the last page of the source file to continue to be used as a template, if the current mPDF document contains more pages than the source file.Default:
false
Note: If you want to turn the template off, just use
$mpdf->SetDocTemplate()
with no parameters. - $continue2pages
-
Values:
1
|0
|true
|false
If
true
(or any positive value) it forces the last 2 pages of the source file to continue to be used alternately as a template, if the current mPDF document contains more pages than the source file. The source file should contain at least 2 pages to enable this functionality. If this option is set totrue
(or any positive value) the$continue
parameter will automatically be set to the same positive value.Default:
false
Note: If you want to turn the template off, just use
$mpdf->SetDocTemplate()
with no parameters.
Changelog
Version | Description |
---|---|
2.3 | Function was added. |
8.* | $continue2pages parameter was added. |
Examples
Example #1
<?php
// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->SetImportUse(); // only with mPDF <8.0
$mpdf->SetDocTemplate('logoheader.pdf',true);
// Do not add page until doc template set, as it is inserted at the start of each page
$mpdf->AddPage();
$mpdf->WriteHTML('Hello World');
// Subsequent pages from logoheader.pdf will be inserted on all subsequent pages
$mpdf->Output();
See Also
- SetImportUse() - Enable the use of imported PDF files or templates
- RestartDocTemplate() - Re-start the use of a Document template from the next page
- Thumbnail() - Print thumbnails of an external PDF file
- SetSourceFile() - Specify the source PDF file used to import pages into the document
- UseTemplate() - Insert an imported page from an external PDF file
- SetPageTemplate() - Specify a page from an external PDF file to use as a template