Forum Moderators: coopster

Message Too Old, No Replies

generating PDF files

         

DrDoc

9:44 am on Apr 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Has anyone had any luck generating PDF files? I want to either convert HTML to PDF or create a PDF on the fly using PHP...

Never tried it, so I'm looking for some pointers...

andreasfriedrich

10:13 am on Apr 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use html2ps to convert HTML to postscript and then convert PS to PDF.

LaTeX is a great way to set really beautiful documents. Create the LaTeX source with PHP [php.net], then run LaTeX and convert the DVI file to PDF.

Andreas

DrDoc

10:37 am on Apr 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...run LaTeX and convert the DVI file to PDF

Can that be done on the fly using a PHP script? I need to be able to produce PDF files for my visitors...

andreasfriedrich

10:46 am on Apr 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure.


system("latex $user.l.tex > $user.l.log2 2>&1");
system("latex $user.l.tex >> $user.l.log2 2>&1");
system("dvipdfm -e -v $user.l.dvi >> $user.l.log2 2>&1");

This will run LaTeX twice (sometimes necessary when using longtables or indices) and then use dvipdfm to convert the DVI file to PDF.

Andreas

DrDoc

10:48 am on Apr 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



aah :)

I'll definitely have to look into this more

Fischerlaender

11:39 am on Apr 14, 2003 (gmt 0)

10+ Year Member



You could use HTMLDOC, which converts HTML files to PDFs on the fly. HTMLDOC is published under GPL. http://www.easysw.com/htmldoc/ [easysw.com].

Fischerlaender

11:46 am on Apr 14, 2003 (gmt 0)

10+ Year Member



Ahh, I forgot to mention FPDF.

From the FPDF-Website:

FPDF is a PHP class which allows to generate PDF files with straight PHP, that is to say without using the PDFlib library. The advantage is that the latter requires a fee for a commercial usage. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.

With FPDF it's easy to create PDF files from within a PHP script:

define('FPDF_FONTPATH','../fpdf151/font/'); 
require('../fpdf151/fpdf.php');
$pdf=new FPDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Arial','B',14);
$pdf->Text(20,20,'FPDF-Demo');
$pdf->Image('logo.jpg',20,50,40);
$pdf->Output();

DrDoc

11:49 am on Apr 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've heard about HTMLDOC and FPDF. But I have no idea what the output looks like. Have you (or anyone else) used HTMLDOC or FPDF before?

Good and bad things?

Fischerlaender

4:06 pm on Apr 14, 2003 (gmt 0)

10+ Year Member



Here is an example page I created with FPDF:
test.certo-it.de/iw/pdfdemo.php
The PHP code for this output is nearly the same as the one I posted before. (I hope it's okay to post this URL as an example someone was asking for ...)

I was using HTMLDOC only for tests, but the output was looking very nice. If you have access to your web server to compile and install HTMLDOC, I would use the latter one. If not, you're limited to FPDF or something similiar.

But be sure to notice the difference:
FPDF creates PDF from scratch within a PHP script whereas HTMLDOC is a standalone HTML-to-PDF converter.

[edited by: jatar_k at 4:14 pm (utc) on April 14, 2003]
[edit reason] delinked [/edit]

DrDoc

7:14 pm on Apr 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Superb! :)

Thank you