How to create a PDF using a PHP library?

Good day,

Could you please recommend any free PHP library to create PDF files?
I have a website for selling books made with HTML, PHP and CSS. After a customer selected some books (and have them in the cart), I’d like to generate a PDF quotation showing all selected books and the total.

Thanks a lot!!

Try this: Convert HTML to PDF with Dompdf

Thanks again!!

Hi Pullo,

I have read Dompdf information.

Could you please confirm what exactly I have to do here to download the library?

Navigate to wherever you want to put the library and execute:

git clone
git submodule init
git submodule update

Thanks a lot!!!

Are you familiar with using GIT?
If not, just navigate here and hit “Download ZIP” button

Hi try this,it’s easy to use…:slight_smile:

Hi Pullo,

I downloaded it. I also discovered how to unpack the ZIP file in cPanel, so I have the library there.

Thanks a lot!!!

Thanks a lot, I’ll check it in case I cannot work with Dompdf.

It might also be worth having a look at jemz solution, too, especially if he can recommend it.


I see you beat me to it :slight_smile:

Hi Pullo,

I started reviewing the documentation of this product.
After making a test .php file with the first sample code and open it with a browser, I get a missing file warning message for dompdf-master/lib/php-font-lib/classes/Font.php, from dompdf-master/ on line 332.

Checking, lines 330 - 333 are:

require_once(DOMPDF_INC_DIR . “/”);
require_once(DOMPDF_LIB_DIR . “/php-font-lib/classes/Font.php”);

But when checking dompdf inner directories, within php-font-lib there is nothing, so the error message is right, there is no classes directory nor font.php file there.
Looking the whole dompdf directory, there is no classes directory nor font.pdf file at all.

Any idea of what am I doing wrong?
Thanks a lot!!!


Sorry that you didn’t get on with the tutorial I linked to.

Did you try mPDF as @jemz ; suggested?

Maybe it would be better if you tell us what you are trying to achieve in a little more detail, then we can consider what the best solution might be.

Hi Pullo,

In the meantime I was able to find the missing files.
I am now in testing process.

This is I’d like to do:
We have an online bookstore. The idea is after the customer selected the books and put them in the cart, to be able to generate a simple PDF quotation showing a quotation number, customer name and e-mail (requested in a previous page), selected books and the total.

Thanks a lot!!

Good stuff.
Let us know if you run into any problems :slight_smile:

Thanks a lot. Based on my requirements, is DomPDF the right tool?

Also, do you know any basic tutorial? :slight_smile:

Yes. It’s a library for generating a PDF from HTML markup and CSS styles (

I thought the SitePoint one I linked to was pretty basic.
I just followed it in 5 minutes and was able to get the basic example working with no problems.

Where are you getting stuck?

Also, check Google for more tutorials:

Hi Pullo,

Once again, thanks a lot for so much help.

I just followed it in 5 minutes and was able to get the basic example working with no problems.

I am feeling like a Neanderthal :slight_smile:

I am still thinking like PHPMailer, where the idea is to build the final e-mail step by step with instructions.
What is the basic strategy with this library? I guess I have to build a webpage of what I want as a PDF outcome. I do not see any instruction to build the PDF step by step.

I have this basic file:


$file= file_get_contents('');

$dompdf = new DOMPDF();


Please open to see the result.
What am I going wrong?

Thanks again!!!


Your approach seems fine to me.

The first thing I would look at is whether your page is valid.
If you run it through the W3C validator you get 7 errors.
I would fix these first and see if it helps the situation.

Hi Pullo,

Thanks a lot.

I am reviewing the errors.
The first one is about “No Character Encoding Found”.
Researching, the suggested code for Latin America is ISO-8859-01. I have added it using two available instructions:

        <meta charset="ISO-8859-01">
        <meta http-equiv="content-type" content="text/html; charset=ISO-8859-01">

It looks well with Internet Explorer, but not with Firefox, please see the page. Characters with accents are not recognized:

Without any character encoding instruction, website is working well. Why should I use one?
Also, can you see if the one I am trying to use is the right one and what am I doing wrong?

Thanks a lot!!!

Hi Pullo,

Please dismiss part of my last post. Website characters are ok with character encoding ISO-8859-1.

Running W3C validator for my test page (, now I get 26 errors and 2 warning.

Without any character encoding instruction, website is working well. Why should I use one?
Before start modifying my website trying to fix errors, could you please confirm if this is the right character encoding for me to use? (for Spanish Latin America).

Thanks a lot!!

I find UTF-8 works well for most languages

But things will get messy if you don’t use it everywhere.

Try losing the “0” i.e.