Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Converting HTML to PDF... the quickest solution

Posted on 2011-02-15
3
Medium Priority
?
470 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
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 …
Progress
Suggested Courses

618 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