Well.Done (c) Radek Hulán [EN]
html2pdf - convert your XHTML to PDF easily

html2pdf - convert your XHTML to PDF easily


I've created html2pdf PHP class, which allows one-click conversion of XHTML to PDF. It is an extension of FPDF class, found on http://www.fpdf.org.

Basic HTML2PDF features:

  • support for bold text, italics, underlined text.
  • support for headlines <h1>, <h2>, <h3> and <h4>.
  • support for linked and embedded images.
  • basic support for tables.
  • full support for lists <li>.
  • full support for <blockquote>.
  • support for pseudo-tags <red>, <blue>.
  • <pre> will be displayed using Courier font, other text with Times New Roman font.
  • support for <br>, <br /> and <p>.
  • support for <hr> and <hr />.
  • exported PDF filename is created by ascii characters of article title.
  • temporary files are deleted after 60 minutes.
  • document header is created with article title, article URI, author, and publishing date.
  • document footer is created with current and total page numbers.
  • built-in support for iconv (character conversions).
  • supplied fonts Times a Courier, in CP1250 encoding (can be used for text in iso-8859-1, iso-8859-2, cp1250, and cp1252, with iconv).

Example of usage:

Main class found in html2pd is createPDF. Its usage is best illustrated by this example:

include ('html2pdf.php');
$pdf =& new createPDF(
 $_POST['html'], // html text to publish
 $_POST['title'], // article title
 $_POST['url'], // article URL
 $_POST['author'], // author name
 time() );

Other possible parameters of html2pdf class can be found in its well commented source code.

File index.php includes online bookmarklet.


Download at https://radekhulan.cz/other/html2pdf.zip.


Supplied fonts are Times and Courier. If you need more fonts, follow a tutorial at www.fpdf.org.


You want to try PDF export right now? Click on [Exports] link just under the current article.

00:24:00 - Sunday, 15.07.07 - category: PHP - 136530x - permalink


Exports: Print [print].


  1. [1] Matt 83.254.77-86.rev.gaoland.net

    comment was put to wastebin by readers

    reply to this comment votes: -10 25.07.2007, 13:54:09
  2. [2] Matt 83.254.77-86.rev.gaoland.net

    comment was put to wastebin by readers

    reply to this comment votes: -10 25.07.2007, 14:12:18
  3. [3] Sergio host80-243-dynamic.8-79-r.retail.telecomitalia.it

    The first four if() statements at the beginning of CloseTag() are buggy.
    Better put some == (equates) instead of = (assignment), do you agree?

    function CloseTag($tag)
    //Closing tag
    if ($tag='H1' || $tag='H2' || $tag='H3' || $tag='H4'){
    if ($tag='PRE'){
    if ($tag='RED' || $tag='BLUE')
    if ($tag='BLOCKQUOTE'){


    reply to this comment votes: 3 24.08.2007, 16:26:30
  4. [4] Mireczech 85-132-136-76-static.vivo.cz

    btw, homepage - http://sourceforge.net/projects/html2fpdf/

    reply to this comment votes: 2 08.12.2007, 09:30:30
  5. [5] Jeff cpe-66-67-2-219.rochester.res.rr.com

    Is it possible to replace selected placeholders in a PDF file with form input data from a user?

    Hope to hear from you soon.

    Many thanks.

    reply to this comment votes: 3 21.02.2008, 20:00:25

Add new comment:

Spam control
New comment