Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing "Download as PDF" on a PHP web page

Tags:

php

pdf

What are the range of options available for implementing a "Download as PDF" feature on a PHP-based web page? Do I need to implement a server-side PHP-based PDF generator using a third party library, or are external web services available that can accomplish this for me?

like image 593
Yarin Avatar asked Dec 11 '10 01:12

Yarin


1 Answers

Use TCPDF over fpdf, because:

  • a) it supports unicode
  • b) it's still being actively maintained
  • c) is based on a more modern OO architecture.

By way of trivia, TCPDF was based upon fpdf many years ago, but was almost entirely remastered since. It still comes with source code and is highly adviseable.

Example usage is another question, and a practive of extending the base class, overriding methods, etc. Don't worry, the download contains lots of samples (10 or more projects) from simple to advanced. I am experienced in PHP, but even taking that into account, some years back, I was able to ship our first prototype of localized pdf reports in all of one day.

class MyPDF extends TCPDF {
   // meaningful code
}

By the way, there's even a TCPDF tag here on StackOverflow :)

like image 189
zanlok Avatar answered Oct 05 '22 19:10

zanlok