Author Topic: PDF from PHP page  (Read 4297 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
PDF from PHP page
« on: March 13, 2013, 03:41:18 PM »
I'm generating some reports for a client of mine and he needs to PDF them. Right now they are just formatted HTML tables and stuff. Is there any easy way to send the output to a PDF?  I have only briefly looked into the PDF functionality in PHP and it looks very manual.

Any help/ideas would be appreciated.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: PDF from PHP page
« Reply #1 on: March 13, 2013, 03:51:49 PM »
I've struggled with this for years. there's never been anything simple.

I did just google it again and the first thing that came up was this API serverice: http://phptopdf.com which looks wicked easy and apparently is free for up to 100 PDF's per month

That said, their website doesn't look very, 'um, legit and I've never heard of them and they don't actually have a paid version of their product yet if you wanted to do more than a 100.

but if you're not to worried about security, you could give them a try and let me know it works!
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: PDF from PHP page
« Reply #2 on: March 13, 2013, 06:53:46 PM »
I'm generating some reports for a client of mine and he needs to PDF them. Right now they are just formatted HTML tables and stuff. Is there any easy way to send the output to a PDF?  I have only briefly looked into the PDF functionality in PHP and it looks very manual.

Any help/ideas would be appreciated.
Print to PDF, it is built into chrome :P

Look at fpdf and pfdi


ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: PDF from PHP page
« Reply #3 on: March 13, 2013, 08:44:21 PM »
@micah... looks interesting.  I agree that it doesn't feel legit.  And I don't think I can limit it to 100.  Since they don't have the premium yet, I wonder if that means that they just don't limit you yet?  Doesn't say how much premium would be either.

@Mike, might have to go with fpdf.  Looks like a pain in the ass.  Problem is, the client is used to using Access (I know, right?).  And the browser puts in the standard header/footer and he doesn't want to turn it off and on all the time, apparently he wants it on most of the time.

Anyways, just seems like a major pain in my ass.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: PDF from PHP page
« Reply #4 on: March 13, 2013, 08:49:10 PM »

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: PDF from PHP page
« Reply #5 on: March 13, 2013, 09:06:25 PM »
A few other options:

https://github.com/dompdf/dompdf
http://webscripts.softpedia.com/script/PHP-Clases/mPDF-70851.html

Most seem to require shoving all your HTML in a variable, which I'm not crazy about, but it's better than manipulating the PDF manually.  I will try these out and post a review.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: PDF from PHP page
« Reply #6 on: March 25, 2013, 10:43:10 PM »
OK, I've literally spent all day on this shit.  Fuckin insane:

http://www.html2pdf.fr/en/default - shit IMHO.  Very picky about how valid the HTML is and I couldn't get past some error about the content of a TD not fitting on a single page... like it can't handle a document that is more than one page??  ARGH.  Documentation is also shit.

https://github.com/dompdf/dompdf - documentation is fucking awful and I couldn't even get this one to function.

phptopdf - one that Micah linked to.  Tried to make it work but I didn't like how insecure it was and it required passing all data through their servers (no thanks).  I didn't give it a valid run because you don't even have the option to 'upgrade' and I didn't want to code it up and then get fucked.

mpdf - http://www.mpdf1.com/mpdf/index.php - Legit.  I dig it.  Easy to setup, documentation is excellent.  I have it working and it looks good so far.  The PDF quality is a little poor but that might be my font choices and stuff.  I'm still tweaking but this should be it.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: PDF from PHP page
« Reply #7 on: March 26, 2013, 05:55:12 AM »
awesome, thanks updating us on your leg work!  Feel free to post anything more you learn about mpdf as you use it (pros/cons/tips/etc)
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: PDF from PHP page
« Reply #8 on: March 26, 2013, 09:03:39 AM »
Will do.  I'll be fucking with it over the next week or so.  I also tried out a few others that didn't seem worth mentioning.  To Mike's suggestion about fpdf.... it seems like a LOT of these libraries are extensions of that.  I also found several that were command line only, so if you're looking elsewhere, just be aware of that.

Betazep

  • Sunk
  • Founders
  • Posts: 1685
  • Karma: +14/-5
Re: PDF from PHP page
« Reply #9 on: March 29, 2013, 12:02:51 AM »
I didn't read all the posts... but what about just saving as HTML and print to PDF? 
"The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents." -Nathaniel Borenstein

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: PDF from PHP page
« Reply #10 on: March 29, 2013, 01:39:17 PM »
No can do.  Need to be able to generate the PDF on the fly.  My client creates reports that go to his clients and he wants to be completely mobile and I don't think his mobile platform has those capabilities.