Thread: html 2 pdf

    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    571
    Rep Power
    51

    html 2 pdf


    Hi:
    I have a business management tool that is written largely in PHP/MySQL with some JavaScript for the UI / forms.

    I would like to convert some pages to pdf on the fly, so that when a customers views their invoice (a PHP file), they have the option to download a copy as a pdf file. Or... from the back office create a pdf file for every customer invoice and append it to an automated email as an attachment.

    Does anyone have a recommendation for a good HTML (PHP) to PDF converter that will plug-in easily to a largely PHP application. I have downloaded "html2ps-2.0.43" but the code is from 2008 and makes use of a lot of deprecated functions.

    Anyone have any alternative suggestions?

    Thanks
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,271
    Rep Power
    4193
    Do you need a pure PHP solution, or are non-php tools an option?

    I've been using html-pdf lately for this task and it seems to work pretty well.

    TCPDF has a writeHTML method that can handle some basic HTML.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    571
    Rep Power
    51
    Originally Posted by kicken
    Do you need a pure PHP solution, or are non-php tools an option?

    I've been using html-pdf lately for this task and it seems to work pretty well.

    TCPDF has a writeHTML method that can handle some basic HTML.
    I'd like a PHP solution if possible. I'm trying to minimize the number of languages for simplicity's sake.

    That said, I notice that "html-pdf" uses "phantomjs" which I am not familiar with. I assume it's a variant of JavaScript. Will I need have this loaded on the hosting company's server or can I load it beneath the path of my application?
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2017
    Location
    Worldwide
    Posts
    48
    Rep Power
    45
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2017
    Posts
    1
    Rep Power
    0
    Originally Posted by SeanF
    I'd like a PHP solution if possible. I'm trying to minimize the number of languages for simplicity's sake.

    That said, I notice that "html-pdf" uses "phantomjs" which I am not familiar with. I assume it's a variant of JavaScript. Will I need have this loaded on the hosting company's server or can I load it beneath the path of my application?
    Do consider a collection of elements to output.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    571
    Rep Power
    51
    Originally Posted by benanamen
    I have looked at the documentation and a tutorial for FPDF:
    Minimal example

    I looks to me as though you have to build the PDF file line by line or block by block:
    ($pdf->Cell(40,10,'Hello World !',1)
    rather than simply converting an entire page of content to pdf. Am I correct?

    I have found an pretty good API which converts entire pages, (pdflayer)
    https://pdflayer.com

    This is very easy to implement and does a good job. The only problem is that for any significant quantity you need a "for fee" API key. Ideally, I'd like to find an application the works in a similar fashion but is free.

    Any ideas?
  12. #7
  13. No Profile Picture
    some internet guy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    the hot aisle
    Posts
    37
    Rep Power
    6
    I know you want to stick to php as a language, but are you opposed to executing other software?

    Theory:
    Install wkhtmltopdf (command line html->pdf)
    use php to save the file as .html
    use exec() to run wkhtmltopdf to convert the html to pdf
    use a cron or something to delete the old html files every X hours or something.

    Might work?
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    571
    Rep Power
    51
    Thanks for the suggestion.... I think that will work. I'll give it a try.

    Thanks again!

IMN logo majestic logo threadwatch logo seochat tools logo