FreeKB - PHP Export to a PDF using DOMPDF
PHP - Export to a PDF using DOMPDF

DOMPDF is software written in PHP which allows you to export HTML pages to PDF. Follow these instructions to download and install DOMPDF. In this tutorial, I will explain how to use DOMPDF on a Linux Web server.

Because of the many dependencies needed by DOMPDF, I usually recommend using other options, such as HTML2PS. HTML2PS is very easy to installl on Linux, using apt-get install or yum install. On the other hand, following is a list of dependencies needed by DOMPDF. HTML2PS also has better support for CSS.

  • PHP version 5 or higher
  • php-mbstring (not available using apt-get install or yum install; download rpm)
  • php-common
  • (64bit)
  • (64bit)
  • (64bit)
  • (64bit)
  • (64bit)
  • (64bit)
  • rtld(GNU_HASH)
  • DOM

In order to use DOMPDF, you need to be running PHP version 5 or higher. To determine the version of PHP being run on your Web server, go to You also will need the mbstring extension and the DOM extension. 

  1. Download the DOMPDF package from Because this tutorial is for Linux, we would download the .tar.gz package.
  2. Extract the contents of the tar gunzip using this command:
tar -zxvf dompdf-version.tar.gz -C /path/to/web/server/root
  1. Remove the origial tar gunzip file.
rm dompdf-version.tar.gz
  1. Add the followiing markup to the PHP page you want to add the export to PDF option.
<form method="post" action="stage.php">
  <textarea name="content" id="content"></textarea>
  <br />
  <input type="submit" name="submit" id="submit" value="create pdf">

include ('dompdf-version/');

  $content = $_POST['content'];
  $dompdf = new DOMPDF();


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 75d33 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |