Solved

Converting HTML to PDF... the quickest solution

Posted on 2011-02-15
3
465 Views
Last Modified: 2013-11-13
I've got a nasty little dynamically generated report in PHP that has a number of charts on it. I'm looking for the quickest (and most portable) way to convert this document into a PDF. I don't care if it converts the whole thing into an image page-by-page... I just want the quickest way to convert this document.

I can't use DOMPDF because my server does not have the DOM extension installed and I can't guarantee that the server this project moves to will have it either.
0
Comment
Question by:cdrugly
  • 2
3 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 34901769
HTML is a markup language - it deals with semantics.  PDF is a page-layout language - it deals with positioning.  These are not like apples and oranges, they are more like fish and bicycles.  They are just two completely different things.

You can use the excellent FPDF class to write a PDF.  It takes a lot of work to get the PDF set up at first, but the class is blazingly fast and highly portable.  Here is the "hello world" exercise in FPDF.
<?php // RAY_fpdf_hello_world.php


// DEMONSTRATE THE BASICS OF FPDF


// BRING IN THE PDF THING
require_once('fpdf16/fpdf.php');

// SYNTHESIZE THE PDF FILE NAME
$pdf_file_link	= '/junk/' . 'temp_pdf_color' . '.pdf';
$pdf_file_name	= getcwd() . $pdf_file_link;

// DO THE HELLO WORLD EXERCISE IN WHITE ON A BLUE BACKGROUND
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->SetFillColor(0,0,255);
$pdf->SetTextColor(255,255,255);
$pdf->Cell(40,10,'Hello World!',0,2,'L', TRUE);

// WRITE THE PDF TO DISK
$pdf->Output($pdf_file_name,'F');

// PRESENT A LINK
echo "<a target=\"my_PDF\" href=\"$pdf_file_link\">PDF</a>\n";

Open in new window

0
 
LVL 2

Author Comment

by:cdrugly
ID: 34906330
I found two interesting options. PDML is a markup language assists in simpler layouts. FPDF is the other. I'm going to give your suggestion a go and report back.
0
 
LVL 2

Author Comment

by:cdrugly
ID: 34943517
While not exactly the fastest (took me about 8 hours to produce the PDF I wanted), FPDF is the best solution. It even works on my clients GoDaddy server (gag).
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP query / monitor data from Telnet to MySQL 7 43
IP 10.0.1.2 / 255.0.0.0 61 54
Wordpress Query 5 24
Do Wend Macro not working 22 26
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question