views:

137

answers:

5

As an example, I have actually been able to generate excel files by changing the content-type for an html document. In this scenario, I would use php to generate the table cells with information gathered from the database and then set the content-type before the page is rendered. Is there a way to do this for pdf's?

+1  A: 

have actually been able to generate excel files by changing the content-type for an html document.

Well, not really: You have been building a HTML file, that Excel happens to be able to parse, and wrongly declaring it as a native Excel file. (I mean no criticism with this - the method works fine within its limitations - but to be exact. :)

As far as I know, this is not possible to do for PDF. You'll have to generate a PDF file using a library, or send the page to a PDF printer on the client's side.

Pekka
What Pekka said. I've had some success with using FPDF: http://www.fpdf.org/
Dave
A: 

You need to use a library to generate the PDF document. You can't just change the content-type like you did for Excel.

Try http://www.fpdf.org/

require('fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
Ed Manet
A: 

As well an fpdf there's also tcpdf which is worth checking out.

Also, if you are interested in generating actual Excel files then have a look at PHPExcel.

Nev Stokes
A: 

If you have a simple HTML then I suggest you use TCPDF to generate your PDF output. Just check out example 6 and 61 on the TCPDF examples page to see how easy it is to generate PDFs based on a subset of HTML.

wimvds
If I go in this direction, how do I format the data? For example, the report I am creating needs certain sections to display within tables with black borders. It would also be helpful if I could display checkboxes and/or radio buttons. Would this be possible? At the very least, how can I display the tables with black borders?
Look at the examples first, because they already show how you add tables with colored/black borders, and lots more. As for checkboxes and radiobuttons, the easiest way to embed these is to replace them by images, though you could also use a font that has these glyphs and render them that way (but that will take some trial and error).
wimvds
+1  A: 

Easiest way to generate PDF is by using DOMPDF. Learn more about DomPDF on Google's Projects.

It is extremely simple:

  1. Generate HTML page
  2. Make a call to DomPDF
  3. Download/Save your PDF

Here is demo showing how easy and fast it is.


Because you are using Joomla you can create PDF view.

Create view called view.pdf.php in the view directory, include template and PDF will be generated automatically. Unfortunately Joomla's PDF is very plain... just text, images and other basic elements.

Alex