How to export a auto generated HTML to PDF

前端 未结 1 416
一生所求
一生所求 2020-12-21 12:48

I have the following code which is partially what my HTML page does.



        
相关标签:
1条回答
  • 2020-12-21 13:13

    You should look at Xep CloudFormatter. This library, jquery plugin, prints any html page. So, given your example, if I were to start with an HTML template like you have, and then with javascript/jquery I populate the html and then call xepOnline.Formatter.Format to render it, you will get back a beautiful PDF.

    I simplified your code a bit, but here is a fiddle for you to explore:

    http://jsfiddle.net/kstubs/56x6W/

    function printMe() {
      tryAtMain();
      var imgLoad = imagesLoaded($('#displayPic')[0]);
      imgLoad.on( 'always', function() {
          xepOnline.Formatter.Format('print_me', {
              pageMargin: ".25in"
          });
      });
    }
    
    function tryAtMain() {
    // some pic
    $('#displayPic').attr('src','http://lorempixel.com/output/abstract-q-c-370-222-1.jpg');
    $('#FullName').html('Johnny Carson');
    }
    
    0 讨论(0)
提交回复
热议问题