### Mpdf: Blank Template Initialization and Output (PHP) Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-functions/addpagebyarray.md Provides an example of initializing Mpdf with a blank template, setting various parameters to their default or empty states, and then outputting the PDF. This serves as a starting point for creating custom PDF documents. ```php WriteHTML('Introduction'); $mpdf->AddPageByArray(array( 'orientation' => '', 'condition' => '', 'resetpagenum' => '', 'pagenumstyle' => '', 'suppress' => '', 'mgl' => '', 'mgr' => '', 'mgt' => '', 'mgb' => '', 'mgh' => '', 'mgf' => '', 'ohname' => '', 'ehname' => '', 'ofname' => '', 'efname' => '', 'ohvalue' => 0, 'ehvalue' => 0, 'ofvalue' => 0, 'efvalue' => 0, 'pagesel' => '', 'newformat' => '', )); $mpdf->WriteHTML('Chapter 1 ...'); $mpdf->Output(); ?> ``` -------------------------------- ### Install Swift Mailer Source: https://github.com/mpdf/mpdf.github.io/blob/master/real-life-examples/e-mail-a-pdf-file.md This command installs the Swift Mailer library using Composer, which is a popular PHP mailer library used for sending emails. ```bash $ composer require swiftmailer/swiftmailer ``` -------------------------------- ### Install mPDF using Composer Source: https://github.com/mpdf/mpdf.github.io/blob/master/installation-setup/installation-v7-x.md This command installs the mpdf/mpdf package using Composer, the standard dependency manager for PHP. Ensure Composer is installed and accessible in your system's PATH. ```bash $ composer require mpdf/mpdf ``` -------------------------------- ### Basic TOC Structure Example Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/html-control-tags/tocpagebreak.md An example demonstrating the basic HTML structure for generating a Table of Contents using mpdf's custom tags. It includes a page break and an entry for the Table of Contents. ```html Text of introduction... Text of main book... ``` -------------------------------- ### Configure mPDF Constructor with Options Source: https://github.com/mpdf/mpdf.github.io/blob/master/installation-setup/installation-v7-x.md This PHP code shows how to instantiate mPDF with custom configuration options passed as an array to the constructor. It illustrates setting the page orientation to Landscape. ```php 'L']); ... ``` -------------------------------- ### Generate PDF with HTML Content using MPDF Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/html-control-tags/annotation.md This snippet demonstrates how to create a new MPDF instance, write basic HTML content to it, and output the generated PDF. It requires the MPDF library to be installed. ```php about which I know very little.'; $mpdf->WriteHTML($html); $mpdf->Output(); ``` -------------------------------- ### MPDF: Changing Headers and Footers with Page Break Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/html-control-tags/pagebreak.md This example illustrates how to define and apply custom headers and footers using the 'pageheader', 'htmlpageheader', and 'pagebreak' tags. It shows how to set different headers for odd and even pages. ```html
My document

Text of introduction...

Text of main book... ``` -------------------------------- ### HTML Example of CSS Float Source: https://github.com/mpdf/mpdf.github.io/blob/master/what-else-can-i-do/floating-blocks.md Demonstrates the practical application of CSS 'float' and 'clear' properties within an HTML structure using mPDF. This example shows how to create floated columns and clear their layout. ```html

CSS Float

Some text to start with
This is text that is set to float:right.
This is text that is set to float:left.
This is text that follows the clear:both.
``` -------------------------------- ### PHP Command Example for mPDF Source: https://github.com/mpdf/mpdf.github.io/blob/master/getting-started/html-or-php.md Demonstrates how to use PHP commands to control mPDF functionality, such as adding bookmarks and writing HTML content. This method is useful for programmatic control within PHP scripts. ```php Bookmark('Start of the document'); $mpdf->WriteHTML('
Section 1 text
'); $mpdf->Output(); ``` -------------------------------- ### HTML Form for User Input and Image Upload Source: https://github.com/mpdf/mpdf.github.io/blob/master/real-life-examples/user-input.md This HTML form allows users to enter text into a textarea and upload an image file. The data is submitted to 'example_userinput2.php' using the POST method and multipart/form-data encoding. ```html
Enter text:


``` -------------------------------- ### MPDF: Basic Page Break Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/html-control-tags/pagebreak.md This example shows a basic page break using the 'pagebreak' tag. It demonstrates how to insert a page break and control the page numbering and suppression. ```html

Text of introduction...

Text of main book... ``` -------------------------------- ### Configure Annotation Margins and Opacity in MPDF Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/html-control-tags/annotation.md This example shows how to configure MPDF to control the placement and transparency of annotation markers within the PDF. It sets the horizontal margin and opacity for annotations before outputting the PDF with HTML content. ```php annotMargin = 10; // The Annotation markers need no transparency as they appear in the margins $mpdf->annotOpacity = 1; $html = 'This is a paragraph about violas about which I know very little.'; $mpdf->Output(); ``` -------------------------------- ### Start New Column with PHP Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/html-control-tags/columnbreak.md Demonstrates how to use the columnbreak tag within HTML content to force a new column. This requires mPDF to be installed and initialized. The SetColumns() function is used to define the number of columns. ```php SetColumns(2); $mpdf->WriteHTML(' Some text... Next column... '); $mpdf->Output(); ?> ``` -------------------------------- ### Generate PDF with Basic Text and Annotation in PHP Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-functions/annotation.md This example shows how to create a new PDF document using MPDF, write basic HTML content, add a simple text annotation, and output the PDF to a file. It demonstrates the fundamental workflow of the MPDF library. ```php WriteHTML('Hello World'); $mpdf->Annotation("Text annotation example"); $mpdf->WriteHTML('Hello World'); $mpdf->Output('filename.pdf'); ?> ``` -------------------------------- ### Generate PDF/A-3 with Embedded Files using mPDF Source: https://context7.com/mpdf/mpdf.github.io/llms.txt This example demonstrates generating a PDF/A-3 compliant document with an embedded XML file using mPDF. It sets the PDF/A version to '3-B' and uses `SetAssociatedFiles` to attach the XML file, specifying its name, MIME type, description, and relationship. The mpdf/mpdf library must be installed. ```php true]); $mpdf2->PDFA = true; $mpdf2->PDFAversion = '3-B'; // PDF/A-3b // Attach invoice XML $mpdf2->SetAssociatedFiles([ [ 'name' => 'invoice.xml', 'mime' => 'text/xml', 'description' => 'ZUGFeRD Invoice Data', 'AFRelationship' => 'Alternative', 'path' => __DIR__ . '/invoice.xml' ] ]); $mpdf2->WriteHTML('

Invoice

PDF/A-3 with embedded XML data.

'); $mpdf2->Output(); ?> ``` -------------------------------- ### Set Header with Text String and Page Numbers (PHP) Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-functions/setheader.md This PHP example shows how to set a header using a text string. It includes placeholders for page numbers and book titles, demonstrating how the '|' character can split the string for left, center, and right alignment. ```php ``` -------------------------------- ### Generate CMYK Colour Charts with mPDF Source: https://github.com/mpdf/mpdf.github.io/blob/master/real-life-examples/colour-charts-cmyk.md This PHP script generates CMYK colour charts by iterating through Cyan, Magenta, Yellow, and Black values, incrementing each by 10. It utilizes the mPDF library to create a PDF document displaying these colour cells and their corresponding values. Ensure the mPDF library is installed via Composer. ```php 'win-1252', 'format' => 'A4-L', ]); $mpdf->useOnlyCoreFonts = true; $mpdf->SetDisplayMode('fullpage'); $mpdf->SetFontSize(6); $pm = 8; // page margin $w = 20; $h = 10; $m = 5; for ($k = 0; $k <= 8; $k++) { // Black - page group for ($y = 0; $y <= 10; $y++) { // Yellow - page group $mpdf->AddPage(); for ($i = 0; $i <= 10; $i++) { // Rows (Magenta) for ($j = 0; $j <= 10; $j++) { // Cols (Cyan) $mpdf->SetXY($pm + ($j * ($w + $m)), $pm + ($i * ($h + $m))); $mpdf->SetFillColor($j * 10, $i * 10, $y * 10, $k * 10); $mpdf->Cell($w, $h, '', 0, 0, 'L', 1); $mpdf->SetXY($pm + ($j * ($w + $m)), $h + $pm + ($i * ($h + $m))); $txt = 'C:' . ($j * 10) . ' M:' . ($i * 10) . ' Y:' . ($y * 10) . ' K:' . ($k * 10); $mpdf->Cell($w, 4, $txt, 0, 0, 'L'); } } } } $mpdf->Output('mpdf.pdf', 'I'); ``` -------------------------------- ### Constructor Configuration for mPDF v7+ Source: https://github.com/mpdf/mpdf.github.io/blob/master/configuration/configuration-v7-x.md Initializes mPDF with specific configuration settings passed as an array to the constructor. This method is recommended for setting up mPDF before generating documents. It requires the Composer autoloader to be included. ```php 'utf-8', 'format' => [190, 236], 'orientation' => 'L' ]); ``` -------------------------------- ### Create A5 Booklet PDF from A4 Source using mPDF Source: https://github.com/mpdf/mpdf.github.io/blob/master/real-life-examples/a5-booklet.md This PHP script demonstrates how to convert an A4 PDF into an A5 booklet format using the mPDF library. It requires the mPDF library to be installed via Composer. The script takes a source PDF, reorders and rotates pages to create a landscape booklet ready for duplex printing, and outputs the resulting PDF. ```php 'A4-L', 'margin_left' => 0, 'margin_right' => 0, 'margin_top' => 0, 'margin_bottom' => 0, 'margin_header' => 0, 'margin_footer' => 0, ]); $mpdf->SetImportUse(); // only with mPDF <8.0 $ow = $mpdf->h; $oh = $mpdf->w; $pw = $mpdf->w / 2; $ph = $mpdf->h; $mpdf->SetDisplayMode('fullpage'); $pagecount = $mpdf->SetSourceFile('A4sourcefile.pdf'); $pp = GetBookletPages($pagecount); foreach ($pp as $v) { $mpdf->AddPage(); if ($v[0] > 0 && $v[0] <= $pagecount) { $tplIdx = $mpdf->ImportPage($v[0], 0, 0, $ow, $oh); $mpdf->UseTemplate($tplIdx, 0, 0, $pw, $ph); } if ($v[1] > 0 && $v[1] <= $pagecount) { $tplIdx = $mpdf->ImportPage($v[1], 0, 0, $ow, $oh); $mpdf->UseTemplate($tplIdx, $pw, 0, $pw, $ph); } } $mpdf->Output(); exit; function GetBookletPages($np, $backcover = true) { $lastpage = $np; $np = 4 * ceil($np / 4); $pp = []; for ($i = 1; $i <= $np / 2; $i++) { $p1 = $np - $i + 1; if ($backcover) { if ($i == 1) { $p1 = $lastpage; } elseif ($p1 >= $lastpage) { $p1 = 0; } } $pp[] = ($i % 2 == 1) ? [ $p1, $i ] : [ $i, $p1 ]; } return $pp; } ``` -------------------------------- ### Mpdf Integration with Custom Client and Loader Source: https://github.com/mpdf/mpdf.github.io/blob/master/configuration/configuration-v7-x.md Demonstrates initializing Mpdf with custom HTTP client and local content loader implementations. This allows for tailored resource handling within Mpdf documents. ```php rewind(); return $response ->withStatus(200) ->withBody($stream); } }; class CustomContentLoader implements \Mpdf\File\LocalContentLoaderInterface, \Psr\Log\LoggerAwareInterface { private $logger; public function __construct(LoggerInterface $logger = null) { $this->logger = $logger ?: new NullLogger(); } public function load($path) { // Will return an empty GIF image for all images not matching the pattern if (!preg_match('/alpha[0-9]{2}/', $path)) { $this->logger->info(sprintf('Custom local content loader ignoring path "%s"', $path)); return base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'); } return file_get_contents($path); } public function setLogger(LoggerInterface $logger) { $this->logger = $logger; } } class StdErrLogger extends \Psr\Log\AbstractLogger { public function log($level, $message, array $context = []) { // fwrite(STDERR, $level . ': ' . $message . "\n"); } } $client = new CustomHttpClient(); $loader = new CustomContentLoader(); $mpdf = new \Mpdf\Mpdf([], new \Mpdf\Container\SimpleContainer([ 'httpClient' => $client, 'localContentLoader' => $loader, ])); $mpdf->setLogger(new StdErrLogger()); ``` -------------------------------- ### Example: Manually Setting Input Encoding with allow_charset_conversion (PHP) Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-variables/allow-charset-conversion.md This example demonstrates how to manually specify the input character encoding using charset_in when allow_charset_conversion is enabled. This is useful when mPDF might not automatically detect the correct encoding. ```php allow_charset_conversion = true; $mpdf->charset_in = 'iso-8859-4'; $mpdf->WriteHTML($html); $mpdf->Output(); ?> ``` -------------------------------- ### mPDF Rounded Border Example Source: https://github.com/mpdf/mpdf.github.io/blob/master/what-else-can-i-do/backgrounds-borders.md Provides a complete CSS example for mPDF demonstrating how to apply a dashed border, background color, rounded corners using 'border-radius', and setting 'background-clip' to 'border-box'. Includes padding for content. ```css div.rounded { border:1mm dashed #220044; background-color: #f0f2ff; border-radius: 3mm / 3mm; background-clip: border-box; padding: 1em; } ``` -------------------------------- ### Example: Parsing ISO-8859-4 HTML with allow_charset_conversion (PHP) Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-variables/allow-charset-conversion.md This example illustrates using allow_charset_conversion to process an HTML document encoded in ISO-8859-4. mPDF will automatically detect and parse the character set when the property is set to true during object instantiation. ```php Document in Lithuanian ... the body of the document encoded in ISO-8859-4 ... '; $mpdf = new \Mpdf\Mpdf(['allow_charset_conversion' => true]); $mpdf->WriteHTML($html); $mpdf->Output(); ?> ``` -------------------------------- ### HTML Example: Absolute Positioned Text Block Source: https://github.com/mpdf/mpdf.github.io/blob/master/what-else-can-i-do/fixed-position-blocks.md Demonstrates using the 'position: absolute' CSS property in HTML to place a text block at a specific location on the page. This example sets the top and left margins to 50mm and defines a width of 100mm for the block. ```html
This is text in a fixed position block element.
``` -------------------------------- ### Mpdf: Customizing Headers and Footers (PHP) Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-functions/addpagebyarray.md Demonstrates defining custom headers and footers by name, both using Mpdf's array-based definition and direct HTML. It also shows how to apply these headers/footers to specific pages and how to disable them. ```php useOddEven = 1; $mpdf->defHeaderByName( 'myHeader', array ( 'L' => array (), 'R' => array (), 'C' => array ( 'content' => 'Chapter 2', 'font-style' => 'B', 'font-family' => 'serif' ), 'line' => 1, ) ); $mpdf->defHTMLHeaderByName( 'myHeader2', '
Chapter 2
' ); $mpdf->WriteHTML('Your Introduction'); // Selects new headers for ODD and EVEN pages to use from the new page onwards // Note the html_ prefix before the named HTML header $mpdf->AddPageByArray(array( 'condition' => 'NEXT-ODD', 'ohname' => 'myHeader', 'ehname' => 'html_myHeader2', 'ohvalue' => 1, 'ehvalue' => 1, )); $mpdf->WriteHTML('Your Book text'); // Turns all headers/footers off from new page onwards $mpdf->AddPage( '','NEXT-ODD','','','','','','','','','', '','','','', -1,-1,-1,-1 ); $mpdf->AddPageByArray(array( 'condition' => 'NEXT-ODD', 'ohvalue' => -1, 'ehvalue' => -1, 'ofvalue' => -1, 'efvalue' => -1, )); $mpdf->WriteHTML('End section of book with no headers'); ?> ``` -------------------------------- ### Change Header/Footer for Odd Page Start in mPDF (PHP) Source: https://github.com/mpdf/mpdf.github.io/blob/master/headers-footers/method-1.md Illustrates how to manage headers and footers when starting a new section on an odd page in a double-sided mPDF document. It uses a conditional page break to ensure the subsequent page is odd before setting the new header. ```php SetHeader('First section header'); $mpdf->SetFooter('First section footer'); $mpdf->WriteHTML('First section text...'); // Use a conditional page-break to ensure you are on an EVEN page before // changing the Header $mpdf->AddPage('','E'); // Now you know that this page-break takes you to an ODD page $mpdf->SetHeader('Second section header'); $mpdf->AddPage(); $mpdf->SetFooter('Second section footer'); $mpdf->WriteHTML('Second section text...'); $mpdf->Output(); ?> ``` -------------------------------- ### Example: Using defaultPageNumStyle with Footer and Page Breaks (PHP) Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-variables/defaultpagenumstyle.md This comprehensive example shows how to use the defaultPageNumStyle variable. It initializes mPDF with a specific style, sets a footer to display the page number, adds content across pages, and demonstrates resetting page numbers and styles using page breaks. ```php 'a']); // Set a simple Footer including the page number $mpdf->setFooter('{PAGENO}'); $mpdf->WriteHTML('Section 1'); $mpdf->WriteHTML('Page a '); // add another page $mpdf->AddPage(); $mpdf->WriteHTML('Section 2 - More content'); $mpdf->WriteHTML(''); $mpdf->WriteHTML('Section 3 - Page with page number starting at 1'); $mpdf->Output(); ?> ``` -------------------------------- ### Method 2: HTML Headers/Footers Source: https://github.com/mpdf/mpdf.github.io/blob/master/headers-footers/headers-footers.md This method allows for the creation of headers and footers using HTML, enabling more complex layouts and the inclusion of images. It's a quick way to program a header/footer once for the whole document. Associated functions include SetHTMLHeader() and SetHTMLFooter(). ```APIDOC ## Method 2: HTML Headers/Footers ### Description The simplest & quickest way to program a header/footer once for the whole document that includes images or uses more complex layout styles. ### Method Not applicable (this describes a conceptual method using associated functions). ### Endpoint Not applicable. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```apidoc // Example using SetHTMLHeader() and SetHTMLFooter() $html_header = '

My HTML Header

'; $mpdf->SetHTMLHeader($html_header); $html_footer = '

My HTML Footer - Page {PAGENO} of {nbpg}

'; $mpdf->SetHTMLFooter($html_footer); ``` ### Response #### Success Response (200) HTML headers and footers are applied to the document. #### Response Example ```json { "status": "success", "message": "HTML headers and footers applied." } ``` ``` -------------------------------- ### Create Basic PDF Document with mPDF Source: https://context7.com/mpdf/mpdf.github.io/llms.txt Demonstrates how to instantiate the mPDF class with default or custom configurations to create PDF documents. It covers setting page size, orientation, margins, and fonts. The generated PDF is then outputted to a file. ```php 'utf-8', 'format' => 'A4', 'default_font_size' => 12, 'default_font' => 'dejavusans', 'margin_left' => 15, 'margin_right' => 15, 'margin_top' => 16, 'margin_bottom' => 16, 'margin_header' => 9, 'margin_footer' => 9, 'orientation' => 'P' // Portrait ]); // Create landscape A4 document $mpdf = new \Mpdf\Mpdf(['format' => 'A4-L']); // Create custom page size (width x height in mm) $mpdf = new \Mpdf\Mpdf([ 'format' => [190, 236], 'orientation' => 'P' ]); $mpdf->WriteHTML('

Hello World

'); $mpdf->Output('document.pdf', \Mpdf\Output\Destination::FILE); ?> ``` -------------------------------- ### Example Usage of aliasNbPg with Header (PHP) Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-variables/aliasnbpg.md This example shows a complete mPDF script that utilizes the 'aliasNbPg' variable. It includes setting up the mPDF object with a custom alias, defining a header that uses this alias, writing some HTML content, and outputting the PDF. This illustrates how the alias is used in conjunction with header/footer functions. ```php '[pagetotal]']); $mpdf->SetHeader('Your header [pagetotal]'); $mpdf->WriteHTML("Hello World"); $mpdf->Output(); ?> ``` -------------------------------- ### Image() Function Reference Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-functions/image.md This section details the Image() function, its parameters, and provides an example of its usage. ```APIDOC ## Image() Function ### Description Embeds an image into the PDF document. ### Method `void Image(string $filename, int $x, int $y, int $width = 0, int $height = 0, string $ext = '', string $href_link = '', bool $paint = true, bool $constrain = true, bool $is_watermark = false, bool $shownoimg = true, bool $allowvector = true)` ### Parameters #### Path Parameters - **$filename** (string) - Required - The path to the image file. - **$x** (int) - Required - The x-coordinate for the image placement. - **$y** (int) - Required - The y-coordinate for the image placement. - **$width** (int) - Optional - The desired width of the image. If 0, the original width is used. - **$height** (int) - Optional - The desired height of the image. If 0, the original height is used. - **$ext** (string) - Optional - The file extension of the image. - **$href_link** (string) - Optional - A URL to link the image to. - **$paint** (bool) - Optional - Whether to paint the image (default: true). - **$constrain** (bool) - Optional - Whether to constrain the aspect ratio (default: true). - **$is_watermark** (bool) - Optional - Whether the image is a watermark (default: false). - **$shownoimg** (bool) - Optional - Whether to show a placeholder if the image is not found (default: true). - **$allowvector** (bool) - Optional - Whether to allow vector images (default: true). ### Request Example ```php Image('files/images/frontcover.jpg', 0, 0, 210, 297, 'jpg', '', true, false); // the last "false" allows a full page picture ?> ``` ### Response This function does not return a value (void). ### See Also * [SetAlpha()] - Set the opacity and blend mode for Images ``` -------------------------------- ### Method 1: Simple String Headers/Footers (Deprecated) Source: https://github.com/mpdf/mpdf.github.io/blob/master/headers-footers/headers-footers.md This method provides a basic way to set headers and footers for the entire document using simple strings. It offers limited styling control and does not support different headers/footers for odd and even pages. Associated functions include SetHeader() and SetFooter(). ```APIDOC ## Method 1: Simple String Headers/Footers (Deprecated) ### Description This is the simplest & quickest way to define a header/footer for the whole document if you need limited control over styling. The simplest form does not allow different header/footer for ODD and EVEN pages. ### Method Not applicable (this describes a conceptual method using associated functions). ### Endpoint Not applicable. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```apidoc // Example using SetHeader() and SetFooter() $mpdf->SetHeader('My Header'); $mpdf->SetFooter('My Footer'); ``` ### Response #### Success Response (200) Headers and footers are applied to the document. #### Response Example ```json { "status": "success", "message": "Headers and footers applied." } ``` ### Related Variables - `$defaultheaderfontsize` - `$defaultheaderfontstyle` - `$defaultheaderline` - `$defaultfooterfontsize` - `$defaultfooterfontstyle` - `$defaultfooterline` ``` -------------------------------- ### Start New Column with AddColumn() in PHP Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-functions/addcolumn.md This PHP code snippet demonstrates how to use the AddColumn() function in mPDF to start a new column. It first sets up two columns using SetColumns(), writes some initial HTML content, then calls AddColumn() to move to the next column, and finally writes content for the new column. The Output() function is called to generate the PDF. ```php SetColumns(2); $mpdf->WriteHTML('Some text...'); $mpdf->AddColumn(); $mpdf->WriteHTML('Next column...'); $mpdf->Output(); ?> ``` -------------------------------- ### Mpdf: Basic Page Writing and Adding Pages (PHP) Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-functions/addpagebyarray.md Demonstrates the fundamental usage of Mpdf to write HTML content and add new pages. It initializes an Mpdf instance and writes initial content before adding a new page for subsequent content. ```php WriteHTML('Your Introduction'); $mpdf->AddPage(); $mpdf->WriteHTML('Your Book text'); ?> ``` -------------------------------- ### Generate Basic Table of Contents with mPDF Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-functions/tocpagebreakbyarray.md This example shows how to create a simple Table of Contents in a PDF document using mPDF. It initializes mPDF, writes some HTML content, adds a page break for the TOC, registers a TOC entry, writes more content, and finally outputs the PDF. ```php WriteHTML('Introduction'); $mpdf->TOCpagebreakByArray(); $mpdf->TOC_Entry("Chapter 1",0); $mpdf->WriteHTML('Chapter 1 ...'); $mpdf->Output(); ?> ``` -------------------------------- ### AliasNbPageGroups() Function Reference Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-functions/aliasnbpagegroups.md This section details the AliasNbPageGroups() function, its parameters, and provides usage examples. ```APIDOC ## AliasNbPageGroups() ### Description Sets the value for the variable string `$aliasNbPgGp`, which is used as a placeholder to insert the total page number into the document. If page numbering has been reset using `AddPage()` or ``, the total number of pages in the current page group will be used instead of the total number of pages in the whole document. ### Method `void AliasNbPageGroups(string $text)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php AliasNbPageGroups('[pagetotal]'); $mpdf->WriteHTML('There are [pagetotal] pages in this page group'); $mpdf->Output(); ?> ``` ### Response #### Success Response (200) This function does not return a value directly, but modifies the internal state of the mPDF object. #### Response Example N/A ### See Also * [Replaceable Aliases](/what-else-can-i-do/replaceable-aliases.html) * [AliasNbPages()](/reference/mpdf-functions/aliasnbpages.html) ``` -------------------------------- ### AddColumn() Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/mpdf-functions/addcolumn.md Starts a new column in the mPDF document. This function is used after setting up columns with SetColumns() or the tag. ```APIDOC ## AddColumn() ### Description Starts a new column in the document. Columns must be set using `SetColumns()` or the `` HTML tag. Height justification for the Columns is disabled when column breaks are set explicitly. **Note:** Columns are incompatible with (and automatically disable): borders for block-level elements (DIV, P etc), table rotation, and collapsible margins for blocks e.g. top and bottom margins for a DIV will not collapse (default) at the top/bottom of a column. ### Method `void` ### Endpoint N/A (This is a function call within the mPDF library) ### Parameters No parameters ### Request Example ```php SetColumns(2); $mpdf->WriteHTML('Some text...'); $mpdf->AddColumn(); $mpdf->WriteHTML('Next column...'); $mpdf->Output(); ?> ``` ### Response #### Success Response N/A (This function does not return a value) #### Response Example N/A ``` -------------------------------- ### Use mPDF with Namespaces (Import Class) Source: https://github.com/mpdf/mpdf.github.io/blob/master/installation-setup/installation-v7-x.md This PHP code demonstrates how to use mPDF by importing the Mpdf class using a 'use' statement. This simplifies referencing the class within the script, applicable to mPDF 7.x and later. ```php percentSubset = 0; $mpdf->SetProtection(array(), '', 'bread'); // Need to specify a password $mpdf->WriteHTML('This copy is XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); $mpdf->Output('test.pdf','F'); // Have to save various encryption keys, which are uniquely generated each document $uid = $mpdf->uniqid; $oval = $mpdf->Ovalue; $encKey = $mpdf->encryption_key; $uval = $mpdf->Uvalue; $pval = $mpdf->Pvalue; $RC128 = $mpdf->useRC128encryption; unset($mpdf); //============================================================== $mpdf = new MpdfMpdf(); $mpdf->SetImportUse(); // only with mPDF <8.0 // Re-instate saved encryption keys from original document $mpdf->encrypted = true; $mpdf->useRC128encryption = $RC128; $mpdf->uniqid = $uid ; $mpdf->Ovalue = $oval ; $mpdf->encryption_key = $encKey ; $mpdf->Uvalue = $uval ; $mpdf->Pvalue = $pval ; $search = array( 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' ); $replacement = array( "personalised for Jos\xc3\xa9 Bloggs" ); $mpdf->OverWrite('test.pdf', $search, $replacement, 'I', 'mpdf.pdf' ) ; ?> ``` -------------------------------- ### sethtmlpagefooter Source: https://github.com/mpdf/mpdf.github.io/blob/master/reference/html-control-tags/sethtmlpagefooter.md Sets a previously defined HTML page footer. You can specify the name of the footer, which pages it applies to (odd, even, or all), and whether to start or stop using it. ```APIDOC ## sethtmlpagefooter ### Description Sets an HTML page footer that has previously been defined by name. ### Method This appears to be a function call within the mPDF library, not a standard HTTP API endpoint. ### Endpoint N/A (Internal function call) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters - **$name** (string) - Optional - The name of the HTML page footer to set. If blank or null, '_default' is used if it exists. Passing '-1' or 'off' will disable the footer. - **$page** (string) - Optional - Specifies whether to set the footer for 'ODD', 'EVEN', or 'ALL' pages in a double-sided document. Defaults to 'ODD' (or all for single-sided). Case-insensitive values: 'O', 'ODD', 'E', 'EVEN', 'ALL'. - **$value** (string) - Optional - Specifies whether to start ('1' or 'ON') or stop ('-1' or 'OFF') using the named footer. Defaults to ignoring, making no changes. ### Request Example ```php // Example of calling the function (within PHP context) // Set the footer named 'myFooter' for all pages $mpdf->SetHTMLFooter('myFooter', 'ALL', '1'); // Disable the default footer $mpdf->SetHTMLFooter('', '', '-1'); ``` ### Response #### Success Response This function modifies the mPDF document's footer settings. It does not return a specific value indicating success or failure in the typical API response sense, but rather alters the internal state of the mPDF object. #### Response Example N/A (Internal function call) ```