Solved

Converting HTML to PDF... the quickest solution

Posted on 2011-02-15
3
464 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

832 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