mPDF Manual – mPDF Utilities

preparePreText()

(htmltoolkit ≥ 2.4, mPDF < 7.0)

PreparePreText – Prepares text to be output ignoring the HTML markup

Description

string preparePreText ( string $text [, string $formfeed ])

Prepares text to be output ignoring the HTML markup. This is useful to output a large text file (e.g. a PHP script file) using WriteHTML(). This will surround the text with <pre> tags whilst preventing <pre> tags included in the text from being parsed. It also allows use of a text string marker ($formfeed) to be replaced by a formfeed in the output file.

Parameters

$text

This parameter specifies the text string to prepare.

$formfeed

$formfeed specifies the string to be replaced by a formfeed in the output file.

Default: "//FF//"

Return value

Returns a text string.

Changelog

Version Description
2.4 Function was added.
7.0 Function was removed.

Examples

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

$text = file_get_contents('scriptfile.php');
$text = preparePreText($text);

// Default spaces/tab in mPDF is 8 as specified by HTML spec.
// Notepad and other text editors use a value of 6
$mpdf->tabSpaces = 6;

// If 'scriptfile.php' is iso-8859-1 or win-1252 encoded, use
$mpdf->allow_charset_conversion = true;
$mpdf->charset_in = 'windows-1252';

$mpdf->WriteHTML($text, \Mpdf\HTMLParserMode::HTML_BODY);

$mpdf->Output();

See Also

  • WriteHTML() - Write HTML code to a PDF file
  • tabSpaces - Specifies the number of spaces to substitue for a TAB character
  • allow_charset_conversion - Parse the character set of any input text from the HTML, or allow setting of the value $charset_in
  • charset_in - Define the character encoding of any input HTML
Fork me on GitHub