Solved

Converting HTML to PDF... the quickest solution

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
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 dynamically set the form action using jQuery.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now