Jump to content

Generate PDF


krystof78

Recommended Posts

Hi guys,

 

I would like to know if there is a way to generate pdf when clicking on a link. In fact, I would like to be able to click on a link and generate a pdf file with information from my database, say a profile of a client for example or an invoice.

 

I was able to generate a pdf using a basic tutorial. Here is the code:

<?php
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Sample PDF, constructed by PHP in real-time.", 50, 750);
PDF_show_xy($mypdf, "Made with the PDF libraries for PHP.", 50, 730);
PDF_end_page($mypdf);
PDF_close($mypdf);

$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen01.pdf");
print $mybuf;

PDF_delete($mypdf);
?>

 

But

1) it's seems to be pretty hard to have something that looks nice if I have to specify each item it location with X and Y

2) I have in the middle of the page: www.pdflib.com. I guess I have to pay for a licence to get rid of that but I went to the website and it's kind of expensive for me.

 

Do you know how an easier way to generate a pdf from my website and without having this "www.pdflib.com"? Is there another script out there or another lib?

 

Thanks for your help.

 

Cheers,

 

Chris

Link to comment
Share on other sites

I can vouch for FPDF - a pleasure to work with!

 

The documentation does a great job of explaining it, though you'll have to put your mind into "graph" mode as the layout usually involves setting an X/Y Coordinate and then having the library do what you need it to do.

Link to comment
Share on other sites

FPDF might not be the best choice. It's pretty outdated right now, does not support Unicode, not really easy to add functionality.

I agree though that it does it's job well (I use it myself in one of my projects).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.