dompdf_config.inc.php
which contains most of the Dompdf configuration. It also loads an autoloader and a custom configuration file in which we can override default configuration parameters.load_html()
method. Alternatively, we can load markup from a file or URL using the load_html_file()
method. It accepts a filename or the URL of a webpage as its argument.render()
method renders the HTML into PDF and we are ready to dump the PDF file. stream()
sends the resulting PDF as an attachment to the browser. The stream()
method has an optional second parameter, an array of options:Accept-Ranges
– boolean, send “Accept-Ranges” header (false by default).Attachment
– boolean, send “Content-Disposition: attachment” header forcing the browser to display a save prompt (true by default).compress
– boolean, enable content compression (true by default).dompdf_config.inc.php
which sets them to their default values. You can change these values by updating the the custom configuration file dompdf_config.custom.inc.php
. Some of the important settings are:DOMPDF_DEFAULT_PAPER_SIZE
– sets the default paper size for the PDF document. Supported paper sizes can be found in include/cpdf_adapter.cls.php
(the default value is “letter”).DOMPDF_TEMP_DIR
– specifies the temporary directory used by Dompdf. Make sure this location is writable by the web server account.DOMPDF_UNICODE_ENABLED
– sets whether the PDF uses Unicode fonts (the default is true).DOMPDF_ENABLE_REMOTE
– enables the inclusion of images or CSS styles from remote sites (default is false).DEBUG_LAYOUT
– whether to render a box around each HTML block in the PDF file which is useful for debugging the layout (default is false).stream()
like in the previous example, we use output()
which returns the PDF as a string. It too accepts an optional options array, but the only option available is compress (the default is true).DOMPDF_ENABLE_PHP
option true.Font_Metrics::get_font()
lets us to create the object we need. We also take the height of the given font at its font size using get_font_height()to calculate positioning for the footer’s contents. The method get_font_width()
returns the width of our text for the given font and font size which is also used in our calculations.line()
method draws a line from point (X1,Y1) to (X2,X2). Notice that the color value we provided is not an actual RGB value. The underlying PDF class requires values between 0 and 1 and so we convert the RGB values into these new values. To get a better approximation, you can divide it by 255.{PAGE_NUM}
and {PAGE_COUNT}
in each page, and makes $pdf
available to us.$dompdf->render()
because we are essentially modifying the rendered PDF.DOMPDF_UNICODE_ENABLED
is true
.Without enabling this setting your text will be re-encoded to Windows ANSIwhen inserted into the PDF and any characters that fall outside thisencoding will be converted to question marks./home/fonts
. To install this font you would go into your dompdfinstallation directory and enter the following command: