3

Possible Duplicate:
Convert HTML + CSS to PDF with PHP?

I'm on a basic Apache with no extensions apart from default enabled and I want to create a PDF file from the current page.

The current page is PHP echoing out some variables but I want to create a PDF document from the HTML and text currently shown on the page.

Something like WHMCS quote system.

Community
  • 1
  • 1
Daryl Gill
  • 5,464
  • 9
  • 36
  • 69
  • I want to avoid the use of extensions, but as a last resort I will enable a few extensions. – Daryl Gill Nov 05 '12 at 22:27
  • Use a PHP library for PDFcreation like http://www.pdflib.com/ – jtheman Nov 05 '12 at 22:28
  • You'll probably have to use [**wkhtmltopdf**](http://code.google.com/p/wkhtmltopdf/) for this. It uses webkits CSS stuff, and supports a lot of options, but it's a bit involved to install on the server. – adeneo Nov 05 '12 at 22:30

6 Answers6

3

You could use a third party solution such as:

http://pdfcrowd.com/

http://www.web2pdfconvert.com/

http://html-pdf-converter.com/

I'd recommend pdfcrowd.com - it has an API that you can use and i've used the service before and not had any problems.

ajtrichards
  • 29,723
  • 13
  • 94
  • 101
2

Look into FPDF, TCPDF, DomPDF, or any other PHP PDF library.

FPDF is very lightweight, and could be perfect for you if you are just echoing out variables.

TCPDF is much more HTML->PDF in terms of syles and css features, but the file size is a bit bigger. It could be used to easily build invoices and make them look nice.

I haven't used DomPDF personally, so I won't comment on it, but it can get the job done.

Tim Withers
  • 12,072
  • 5
  • 43
  • 67
1

Take a look at FPDF.

It is a free libary for generating .pdf documents within php.

mas-designs
  • 7,498
  • 1
  • 31
  • 56
  • 1
    FPDF is great, but it will not convert HTML to PDF. – GolezTrol Nov 05 '12 at 22:29
  • I have a predefined quote which is set out using HTML and CSS for the style. Using PHP to pull information on the quote from a MYSQL Database, I need to create a PDF file from the exact layout – Daryl Gill Nov 05 '12 at 22:30
  • @DarylGill You haven't got much options. PHP doesn't contain a HTML renderer. Rendering HTML with styles is pretty damn complex and renderers are highly specialized pieces of code. Some renderes may render HTML to a certain extent, though, but I'm not sure about the results. It won't have the power of a full webbrowser. – GolezTrol Nov 05 '12 at 22:33
0

I've used TCPDF to create a PDF from HTML. I think DOMPDF also does that

you have a few options:

http://php.net/manual/en/book.pdf.php

FPDF: http://www.fpdf.org/

TCPDF: http://www.tcpdf.org/

DOMPDF: http://code.google.com/p/dompdf/

BTW: Convert HTML + CSS to PDF with PHP?

Community
  • 1
  • 1
galchen
  • 5,252
  • 3
  • 29
  • 43
0

You can also check dompdf . It creates pdf FROM HTML ! it could be more appropriate for your request but I personally prefer FPDF (CSS make me sometimes crazy with domdf :-) )

clement
  • 4,204
  • 10
  • 65
  • 133
0

The only pure PHP solution I've tested is mPDF and it worked pretty well for my purpose. It takes HTML/CSS input at generates a PDF from that.

It requires a lot of memory so you'll have to increase the memory limit for the script. The settings that worked for me were:

ini_set('memory_limit', '1024M');
ini_set('pcre.backtrack_limit', 2000000);
h00ligan
  • 1,471
  • 9
  • 17
  • 1
    a lot of memory will need for all pdf libraries (tcpdf, mpdf etc). so if in project you need simple invoice with max 5 pages it will work good, but if need to generate big pdf files, then better use serverside generation, for example wkhtmltopdf – DTukans Nov 05 '12 at 23:24