### Start a New Column with columnbreak Source: https://mpdf.github.io/reference/html-control-tags/columnbreak.html Demonstrates how to use the HTML tag within WriteHTML to explicitly start a new column. This requires setting up columns first using SetColumns(). ```php SetColumns(2); $mpdf->WriteHTML(' Some text... Next column... '); $mpdf->Output(); ``` -------------------------------- ### Basic Formfeed Example Source: https://mpdf.github.io/reference/html-control-tags/formfeed.html Demonstrates the basic usage of the formfeed tag to force content onto a new page. ```html
Text of introduction... This text will start on a new page, and will also have a blue border etc...
``` -------------------------------- ### Cascaded CSS Example Source: https://mpdf.github.io/about-mpdf/changelog.html Example illustrating cascaded CSS rules in mPDF. ```css div.topic table.type1 td ``` -------------------------------- ### Multi-column Index Setup with HTML Source: https://mpdf.github.io/what-else-can-i-do/index.html Generate a multi-column index by defining column layout using the `` tag before and after the `` tag. ```html

Index

``` -------------------------------- ### Enable Debugging in mPDF Source: https://mpdf.github.io/reference/mpdf-variables/debug.html This example demonstrates how to enable debugging when creating a new mPDF instance. Set 'debug' to true to throw \Mpdf\MpdfException for potential errors. ```php true]); $mpdf->WriteHTML("Hello World"); $mpdf->Output(); ``` -------------------------------- ### Blank Template Example with AddPageByArray Source: https://mpdf.github.io/reference/mpdf-functions/addpagebyarray.html Illustrates using AddPageByArray with all parameters set to their default or empty values, effectively creating a blank template page. ```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(); ``` -------------------------------- ### Add a new page with specific parameters Source: https://mpdf.github.io/reference/mpdf-functions/addpagebyarray.html This example shows adding a new page with custom settings for margins, headers, and footers using AddPageByArray(). ```php $mpdf->AddPageByArray([ 'margin-left' => $mpdf-> 0, 'margin-right' => $mpdf-> 0, 'margin-top' => $mpdf-> 0, 'margin-bottom' => $mpdf-> 0, 'margin-header' => $mpdf-> 0, 'margin-footer' => $mpdf-> 0, 'odd-header-name' => 'Header1', 'even-header-name' => 'Header2', 'odd-footer-name' => 'Footer1', 'even-footer-name' => 'Footer2', ]); ``` -------------------------------- ### Example of Media Attribute in Style Tag Source: https://mpdf.github.io/about-mpdf/changelog.html Shows how to use the media attribute within a style tag. ```html ``` -------------------------------- ### Example of Media Attribute in Link Tag Source: https://mpdf.github.io/about-mpdf/changelog.html Demonstrates using the media attribute with a linked stylesheet. ```html ``` -------------------------------- ### CSS Float Example Source: https://mpdf.github.io/what-else-can-i-do/floating-blocks.html Demonstrates how to use 'float: right' and 'float: left' with specified widths for block elements, followed by 'clear: both' to reset the 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.
``` -------------------------------- ### CSS Class and ID Selectors Source: https://mpdf.github.io/about-mpdf/changelog.html Example demonstrating support for distinct CSS selectors for tags, classes, and IDs. ```css h5 {...} .h5 {...} #h5 {...} ``` -------------------------------- ### CSS Gradient Formats Source: https://mpdf.github.io/css-stylesheets/supported-css.html Shows examples of supported CSS gradient syntaxes for background images, including Mozilla-specific and draft CSS3 formats. ```css background: -moz-repeating-linear-gradient(red, blue 20px, red 40px); background-image: -moz-repeating-linear-gradient(red, blue 20px, red 40px); background: linear-gradient(top, #c7cdde, #f0f2ff); background-image: linear-gradient(top, #c7cdde, #f0f2ff); ``` -------------------------------- ### Add a Simple Bookmark to a PDF Source: https://mpdf.github.io/reference/mpdf-functions/bookmark.html Demonstrates how to add a basic bookmark to the beginning of a PDF document using the Bookmark() function. This is useful for marking the start of content. ```php Bookmark('Start of the document'); $mpdf->WriteHTML('
Section 1 text
'); $mpdf->Output('filename.pdf'); ``` -------------------------------- ### Setting Up and Using Columns in mPDF Source: https://mpdf.github.io/reference/html-control-tags/columns.html Demonstrates how to initialize mPDF, set up a three-column layout with justified vertical alignment and a specific column gap, write content, and use a column break. This is useful for creating complex page layouts with distinct content areas. ```php WriteHTML(''); $mpdf->WriteHTML('Some text...'); $mpdf->WriteHTML(''); $mpdf->WriteHTML('Next column...'); $mpdf->Output(); ``` -------------------------------- ### Formfeed with Page Number Reset Source: https://mpdf.github.io/reference/html-control-tags/formfeed.html This example demonstrates using the formfeed tag to add a new page and reset the page number to 1. This is useful for starting a new section with a clean page count. ```html ``` -------------------------------- ### Set User and Owner Passwords with Permissions Source: https://mpdf.github.io/reference/mpdf-functions/setprotection.html Demonstrates setting user and owner passwords along with specific user permissions. The first part shows setting a user password to open the file and an owner password for full rights. The second part shows no user password required to open, but an owner password for full rights, and grants the user copy and print permissions. ```php SetProtection(array(), 'UserPassword', 'MyPassword'); // Encrypt the file and grant permissions to the user to copy and print // No password is required to open the document // Owner has full rights using the password "MyPassword" $mpdf->SetProtection(array('copy','print'), '', 'MyPassword'); ``` -------------------------------- ### Using SetPageTemplate() to Add a PDF Page Template Source: https://mpdf.github.io/reference/mpdf-functions/setpagetemplate.html This example demonstrates how to set a page from an external PDF file as a template for all subsequent pages in an mPDF document. Ensure the PDF file is correctly specified and imported before setting it as a template. The template is automatically added at the start of each new page. ```php SetImportUse(); // only with mPDF <8.0 $pagecount = $mpdf->SetSourceFile('logoheader.pdf'); $tplId = $mpdf->ImportPage($pagecount); $mpdf->SetPageTemplate($tplId); // Do not add page until page template set, as it is inserted at the start of each page $mpdf->AddPage(); $mpdf->WriteHTML('Hello World'); // The template $tplId will be inserted on all subsequent pages until (optionally) // $mpdf->SetPageTemplate(); $mpdf->Output(); ``` -------------------------------- ### Setting up 2 Columns with Justified Height and 3mm Gap Source: https://mpdf.github.io/reference/mpdf-functions/setcolumns.html This example demonstrates how to set up two columns with justified vertical alignment and a 3mm gap between them using the SetColumns() function. It then writes HTML content and adds a new column. ```php SetColumns(2, 'J', 3); $mpdf->WriteHTML('Some text...'); $mpdf->AddColumn(); $mpdf->WriteHTML('Next column...'); $mpdf->Output(); ``` -------------------------------- ### Install Swift Mailer Source: https://mpdf.github.io/real-life-examples/e-mail-a-pdf-file.html Use Composer to install the Swift Mailer library, which is required for sending emails. ```bash $ composer require swiftmailer/swiftmailer ``` -------------------------------- ### Initialize mPDF Instance Source: https://mpdf.github.io/reference/mpdf-functions/construct.html This snippet shows the basic initialization of an mPDF object using the __construct() method. It then writes 'Hello World' to the document and outputs it as a PDF file named 'filename.pdf'. Ensure the composer autoload is required. ```php WriteHTML('Hello World'); $mpdf->Output('filename.pdf'); ``` -------------------------------- ### Single Cell Border Example Source: https://mpdf.github.io/about-mpdf/changelog.html Example of a table with a single cell and a border, highlighting a potential rendering issue. ```html ... ``` -------------------------------- ### Basic dottab Usage Source: https://mpdf.github.io/reference/html-control-tags/dottab.html Demonstrates the basic insertion of dots using the '' tag to right-align text, simulating a menu item with a price. ```php &nbsp;£7.95'; $mpdf->WriteHTML($menuitem); ?> ``` -------------------------------- ### Setting Display Preferences for a PDF Source: https://mpdf.github.io/reference/mpdf-functions/setdisplaypreferences.html This example demonstrates how to set multiple display preferences for a PDF document, including hiding the menu bar and toolbar, and displaying the document title. This is useful for creating a more immersive reading experience. ```php SetDisplayPreferences('/HideMenubar/HideToolbar/DisplayDocTitle'); $mpdf->WriteHTML(' Hello World '); $mpdf->Output('filename.pdf'); ``` -------------------------------- ### Basic Text Annotation Source: https://mpdf.github.io/reference/mpdf-functions/annotation.html Adds a simple text annotation to the PDF document. This is a basic example of using the Annotation function. ```php WriteHTML('Hello World'); $mpdf->Annotation("Text annotation example"); $mpdf->WriteHTML('Hello World'); $mpdf->Output('filename.pdf'); ``` -------------------------------- ### Select Multiple Attribute Source: https://mpdf.github.io/html-support/html-attributes.html Example of using the 'multiple' attribute for a select element, allowing users to select multiple options. ```html
``` -------------------------------- ### CSS font-feature-settings Examples Source: https://mpdf.github.io/fonts-languages/opentype-layout-otl.html Examples of using CSS 'font-feature-settings' to control various OpenType features such as small caps, historical forms, ligatures, tabular figures, fractions, and stylistic sets. ```css /* use small-cap alternate glyphs */ .smallcaps { font-feature-settings: "smcp" on; } ``` ```css /* convert both upper and lowercase to small caps (affects punctuation also) */ .allsmallcaps { font-feature-settings: "c2sc", "smcp"; } ``` ```css /* enable historical forms */ .hist { font-feature-settings: "hist"; } ``` ```css /* disable common ligatures, usually on by default */ .noligs { font-feature-settings: "liga" 0; } ``` ```css /* enable tabular (monospaced) figures */ td.tabular { font-feature-settings: "tnum"; } ``` ```css /* enable automatic fractions */ .fractions { font-feature-settings: "frac"; } ``` ```css /* use the second available swash character */ .swash { font-feature-settings: "swsh" 2; } ``` ```css /* enable stylistic set 7 */ .fancystyle { font-family: Gabriola; /* available on Windows 7, and on Mac OS */ font-feature-settings: "ss07"; } ``` -------------------------------- ### Incremental HTML Writing with Initialise and Close Parameters Source: https://mpdf.github.io/reference/mpdf-functions/writehtml.html This example shows how to write HTML content in parts by controlling the initialization and closing of HTML elements. The first call initializes buffers, subsequent calls append content without re-initializing or closing, and the final call closes all elements. ```php WriteHTML('This is the beginning...', \ Mpdf\ HTMLParserMode::HTML_BODY, true, false); $mpdf->WriteHTML('...this is the middle...', \ Mpdf\ HTMLParserMode::HTML_BODY, false, false); $mpdf->WriteHTML('...and this is the end', \ Mpdf\ HTMLParserMode::HTML_BODY, false, true); ``` -------------------------------- ### HTML Example with CJK Characters from TTC Fonts Source: https://mpdf.github.io/fonts-languages/fonts-in-mpdf-6-x.html Use CSS font-family to select specific fonts from a TrueType Collection (TTC) for rendering CJK characters. This example demonstrates selecting fonts from 'mingliu.ttc' and 'mingliub.ttc'. ```html
鼂 鼦 齄 齐 齢 齩 𣊉 𣊊
鼂 鼦 齄 齐 齢 齩 𣊉 𣊊
鼂 鼦 齄 齐 齢 齩 𣊉 𣊊
``` -------------------------------- ### Setting Basic Keywords Source: https://mpdf.github.io/reference/mpdf-functions/setkeywords.html Demonstrates how to set simple text keywords for the document metadata using SetKeywords(). ```php SetKeywords('My Keywords, More Keywords'); $mpdf->WriteHTML('Hello World'); $mpdf->Output('filename.pdf'); ?> ``` -------------------------------- ### Custom Progress Bar HTML Example Source: https://mpdf.github.io/reference/mpdf-variables/progbar-althtml.html Example of setting the progbar_althtml variable to display custom HTML content in the progress bar. The HTML should include and tags but no closing tags. It can also include sections for stylesheets. ```php '.progbar_althtml=>'Creating PDF file. Please wait...' ``` -------------------------------- ### PHP mPDF Example with Custom Headers and Footers Source: https://mpdf.github.io/paging/using-page.html This example demonstrates how to use `page-break-before` with named page definitions to customize headers and footers for different sections of a document. It utilizes mPDF's `useOddEven` property to enable distinct odd and even page headers/footers. ```php useOddEven = 1; $html = '
My document
My document
{DATE j-m-Y} {PAGENO}/{nbpg} My document
My document {PAGENO}/{nbpg} {DATE j-m-Y}
Chapter 2
Chapter 2
Chapter 2 Footer
Chapter 2 Footer
Hello World
Text of Chapter 2
No-Header page
'; $mpdf->WriteHTML($html); $mpdf->Output(); ``` -------------------------------- ### PHP: Start a New Column with AddColumn() Source: https://mpdf.github.io/reference/mpdf-functions/addcolumn.html Demonstrates how to use AddColumn() to create a new column after writing some HTML content. Ensure SetColumns() or is used prior to calling AddColumn(). ```php SetColumns(2); $mpdf->WriteHTML('Some text...'); $mpdf->AddColumn(); $mpdf->WriteHTML('Next column...'); $mpdf->Output(); ?> ``` -------------------------------- ### Mpdf Constructor Configurations Source: https://mpdf.github.io/reference/mpdf-functions/construct.html Demonstrates initializing the Mpdf class with different modes, formats, and orientations. Use 'utf-8' mode for standard web content and 'en-GB' for specific language settings. Page formats can be specified by name (e.g., 'A4-L') or by custom dimensions. ```php 'utf-8']); // Define a new \Mpdf\Mpdf document using win-1252 fonts based on a language/country code $mpdf = new \Mpdf\Mpdf(['mode' => 'en-GB']); // Define a Landscape page size/format by name $mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4-L']); // Define a page size/format by array - page will be 190mm wide x 236mm height $mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => [190, 236]]); // Define a page using all default values except "L" for Landscape orientation $mpdf = new \Mpdf\Mpdf(['orientation' => 'L']); ``` -------------------------------- ### Change Header/Footer for Odd Page Start Source: https://mpdf.github.io/headers-footers/method-1.html Illustrates how to ensure a new section starts on an odd page in a double-sided document. It uses a conditional page break ('E' for even page) to land on an even page, ensuring the subsequent AddPage() results in an odd page for the new section's 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(); ``` -------------------------------- ### Initialize mPDF with forcePortraitHeaders enabled Source: https://mpdf.github.io/reference/mpdf-variables/forceportraitheaders.html Demonstrates how to set the 'forcePortraitHeaders' option to true during mPDF document initiation. ```php true]); ``` -------------------------------- ### Special CSS 'thead-underline' Source: https://mpdf.github.io/about-mpdf/changelog.html Example of using the special CSS 'thead-underline' for table headers. ```css /* Special CSS 'thead-underline' */ ``` -------------------------------- ### Columns Source: https://mpdf.github.io/reference/mpdf-functions/overview.html Functions for controlling the use of multiple columns on a page and starting new columns. ```APIDOC ## SetColumns() ### Description Controls the use of multiple columns on the page. ### Method N/A (Method of mPDF class) ### Endpoint N/A ### Parameters None explicitly documented for direct user invocation in this context. ### Response N/A ## AddColumn() ### Description Starts a new column. ### Method N/A (Method of mPDF class) ### Endpoint N/A ### Parameters None explicitly documented for direct user invocation in this context. ### Response N/A ``` -------------------------------- ### Setting a Simple Creator String Source: https://mpdf.github.io/reference/mpdf-functions/setcreator.html Demonstrates how to set a basic string as the document's Creator using SetCreator(). ```php SetCreator('My Creator'); $mpdf->WriteHTML('Hello World'); $mpdf->Output('filename.pdf'); ``` -------------------------------- ### AddColumn() Source: https://mpdf.github.io/reference/mpdf-functions/addcolumn.html Starts a new column in the mPDF document. This function is part of the multi-column layout feature. ```APIDOC ## AddColumn() ### Description Starts a new column in the document. Columns must be set using `SetColumns()` or ``. **Note:** Columns are incompatible with borders for block-level elements, table rotation, and collapsible margins. ### Method `void AddColumn()` ### Parameters No parameters. ### Examples ```php SetColumns(2); $mpdf->WriteHTML('Some text...'); $mpdf->AddColumn(); $mpdf->WriteHTML('Next column...'); $mpdf->Output(); ?> ``` ### See Also * `` - HTML equivalent to AddColumn() * `SetColumns()` - Control the use of multiple columns on the page * `` - Control the use of multiple columns on the page ``` -------------------------------- ### Set Default Page Size and Add New Page Source: https://mpdf.github.io/paging/page-size-orientation.html Demonstrates setting the default page size to 'Legal' and adding a new page with Landscape orientation. ```php 'Legal']); $mpdf->WriteHTML('Hello World'); $mpdf->AddPage('L'); // Adds a new page in Landscape orientation $mpdf->WriteHTML('Hello World'); $mpdf->Output(); ``` -------------------------------- ### Setting a Simple Document Title Source: https://mpdf.github.io/reference/mpdf-functions/settitle.html Demonstrates how to set a basic string as the document title using SetTitle(). This is useful for standard document titling. ```php SetTitle('My Title'); $mpdf->WriteHTML('Hello World'); $mpdf->Output('filename.pdf'); ?> ``` -------------------------------- ### Generate Document Index with CreateIndex() Source: https://mpdf.github.io/reference/mpdf-functions/createindex.html This example demonstrates how to use the CreateIndex() function to generate a document index. It first adds an index entry using IndexEntry(), then creates the index itself with custom parameters for columns, font size, line spacing, offset, dividing letters, column gap, and fonts. ```php WriteHTML('Beginning bit of document...'); $mpdf->IndexEntry("Buffalo"); $mpdf->WriteHTML('Your text which refers to a buffalo, which you would like to see in the Index'); $mpdf->AddPage(); $mpdf->WriteHTML('

Index

',2); $mpdf->CreateIndex(2, '', '', 3, 1, '', 5, 'serif','sans-serif'); $mpdf->Output(); ``` -------------------------------- ### Absolute Positioning Example Source: https://mpdf.github.io/what-else-can-i-do/fixed-position-blocks.html Places a div element at a fixed position (50mm from top and left) with a specified width on the page. ```html
This is text in a fixed position block element.
``` -------------------------------- ### Rotated Text in Table Cells Source: https://mpdf.github.io/about-mpdf/changelog.html Example of setting rotated text within a table row using inline styles. ```html