Solved

Converting HTML to PDF... the quickest solution

Posted on 2011-02-15
3
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

691 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