doujiyun0041 2016-09-30 16:25
浏览 221

使用HTML字符串中的wkhtmltopdf导出为PDF

I have a website with HTML/CSS and a JavaScript generated inline datepicker. You can mark days in datepicker.

I want to export the whole content with the marks in datepicker as a PDF.

With Client-Side jsPDF and canvas2html I have a problem with position and sizes. I get partial content in the PDF only (begin or end from datepicker).

Now I try it with wkhtmltopdf.

I get the HTML with $("#datepicker").html() and send it to a PHP Script. It works with a test string, but I get a blank pdf when I use real data.

$.ajax({
  data: 'htmlstring=' + escape($("#datepicker").html()),
  url: 'http://example.com/htmltopdf.php',
  method: 'POST',
  success: function(msg) {
   alert(msg);
  }
});

<?php
  $htmlString = $_POST["htmlstring"];
  //$htmlString = rawurldecode($htmlString);
  exec('echo "<html><head></head><body>' . $htmlString . '</body></html>" | /usr/local/bin/wkhtmltopdf --encoding UTF-8 - export.pdf');
?>

I also like a different working solution.

  • 写回答

1条回答 默认 最新

  • doulian4762 2016-09-30 18:34
    关注
    data: {
       htmlstring: escape($("#datepicker").html())
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题