Forum Moderators: coopster

Message Too Old, No Replies

Writing html into a PDF file

Can't generate content-rich PDFs

         

anshul

7:42 am on Mar 31, 2005 (gmt 0)

10+ Year Member



Simple code for generating a .pdf document is:

<?php

$pdf = pdf_new();
pdf_open_file ($pdf);
pdf_begin_page($pdf, 595, 842);
$font = pdf_findfont($pdf, "Times New Roman", "winansi", 1);
if ($font) {
pdf_setfont($pdf, $font, 10);
}

pdf_set_value($pdf, "textrendering", 1);
pdf_set_info ($pdf, "Author", "guide");
pdf_set_info ($pdf, "Keywords", "How, r, u");

pdf_show_xy($pdf, "A PDF document <B>created</B> in memory!", 50, 750);
pdf_show_xy($pdf, "A PDF document <B>created</B> in memory!", 50, 770);
pdf_show_xy($pdf, "A PDF document <B>created</B> in memory!", 50, 790);
pdf_show_xy($pdf, "A PDF document <B>created</B> in memory!", 50, 810);
pdf_show_xy($pdf, "A PDF document <B>created</B> in memory!", 50, 830);
pdf_end_page($pdf);
pdf_close($pdf);

$data = pdf_get_buffer($pdf);

header("Content-type: application/pdf");
header("Content-disposition: inline; filename=test.pdf");
header("Content-length: " . strlen($data));

echo $data;

?>

But how to write images, links, colors, tables ( i.e., html elements ) into a .pdf file :¦

coopster

11:49 am on Mar 31, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you tried the free version, which is a class as opposed to an external library, called FPDF?


On the PHP PDF functions [php.net] page, you will find this note..
Note: If you're interested in alternative free PDF generators that do not utilize external PDF libraries, see this related FAQ [php.net].

The FPDF site has tutorials and working examples with a bunch of donated additions to accomplish most any task you wish.