Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Sep 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to convert HTML to PDF through JS

    In my application,I want to export my HTML as PDF.
    So Please suggest how to convert HTML to PDF through JS

    I tried htmlToCanvas approach to convert page to Image and then Image to PDF through Java but htmlToCanvas not supported in IE8.

    So not working in IE8.

    Please suggest any approach which is compatible with all browsers.

  • #2
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    Javascript is not made to work with files... PHP seems a better choice to build rtf or pdf files.
    Then you have probably to use Ajax to work on the serveur.
    A search PHP to PDF give many solutions...
    Using templates, it is relatively easy to build rich text format files with php.
    Then exec ou shell_exec allow to execute external programs to convert rtf to pdf.
    Last edited by 007julien; 02-17-2014 at 09:52 AM.

  • #3
    New Coder
    Join Date
    Sep 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In my application,I can't use PHP.Please suggest any approach in JS and Java

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,225
    Thanks
    23
    Thanked 606 Times in 605 Posts
    If an online converter would work for you look here http://pdfcrowd.com/#convert_by_url
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,349
    Thanks
    11
    Thanked 589 Times in 570 Posts
    the big js pdf generators i know (jspdf, ) uses HTML5, and IE8 doesn't support HTML5 since it came out before HTML5 got off the ground.

    you can give the IE8 uses an HTML instead, ship to a server to build the PDF, or tell the user to get a browser made in the last five years.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,349
    Thanks
    11
    Thanked 589 Times in 570 Posts
    Quote Originally Posted by 007julien View Post
    Javascript is not made to work with files...
    JS had file support from the start in netscape's SJS solutions. It's not a language that defines input and output; it depends on the host environment to provide any input or output capabilities, files or otherwise. For example, Node.js has excellent file capabilities using ultra-efficient low-level C++ libraries. As other host environments have matured, JS, even browser JS, now has access to user file input via drag and drop and <input type=file> and output using <a download>, dataURLs, and FileWriter.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Quote Originally Posted by rnd me View Post
    the big js pdf generators i know (jspdf, ) uses HTML5, and IE8 doesn't support HTML5 since it came out before HTML5 got off the ground.

    you can give the IE8 uses an HTML instead, ship to a server to build the PDF, or tell the user to get a browser made in the last five years.
    From the jspdf site, it says:
    jsPDF will work in IE6+*, Firefox 3+, Chrome, Safari 3+, Opera. For IE9 and below, we lazily load a Flash shim called Downloadify which enables the files to be downloaded. (Current build does not have IE6-9 shim enabled)

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,349
    Thanks
    11
    Thanked 589 Times in 570 Posts
    Quote Originally Posted by glenngv View Post
    From the jspdf site, it says:
    good eye, problem solved!
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #9
    New Coder
    Join Date
    Sep 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for reply.
    But As per my understanding,jsPdf is used to download PDF from image buffer data.
    In addImage method of jsPDF.js,need to provide imagebuffer as an input.
    But My concern area is to convert HTML data For eg:<input type="text"/>
    to Image first.That's why I was using HTMLCanvas.
    I just want to print a big HTML to PDF.which I can't do directly so need to convert to Image first.From image to PDF I am converting through Java.
    Please suggest.

  • #10
    hgs
    hgs is offline
    New Coder
    Join Date
    Jan 2010
    Location
    Germany
    Posts
    83
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Why not just print into a PDF-file ?
    My site
    If you’re doing software development right, you’re probably doing Agile wrong.
    -- Isaac Schlueter

  • #11
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Quote Originally Posted by minakshi View Post
    Thanks for reply.
    But As per my understanding,jsPdf is used to download PDF from image buffer data.
    In addImage method of jsPDF.js,need to provide imagebuffer as an input.
    But My concern area is to convert HTML data For eg:<input type="text"/>
    to Image first.That's why I was using HTMLCanvas.
    I just want to print a big HTML to PDF.which I can't do directly so need to convert to Image first.From image to PDF I am converting through Java.
    Please suggest.
    In the jspdf site, there's a sample, HTML Renderer (Early stages), that generates pdf from a specific html markup on the page using the fromHTML() method.

  • #12
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,349
    Thanks
    11
    Thanked 589 Times in 570 Posts
    Quote Originally Posted by hgs View Post
    Why not just print into a PDF-file ?
    how is that going to work on the majority of user agents (tablet/mobile) sold today?
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #13
    hgs
    hgs is offline
    New Coder
    Join Date
    Jan 2010
    Location
    Germany
    Posts
    83
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by rnd me View Post
    how is that going to work on the majority of user agents (tablet/mobile) sold today?
    I had print drivers in my mind, like on PC's .
    On tablets / mobile ... I have no idea
    My site
    If you’re doing software development right, you’re probably doing Agile wrong.
    -- Isaac Schlueter


  •  

    LinkBacks (?)

    1. 07-01-2014, 04:27 AM

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •