使用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个回答



  data:{
htmlstring:escape($(“#datepicker”)。html())
} \ n </ code> </ pre>
</ div>

展开原文

原文

data: {
   htmlstring: escape($("#datepicker").html())
}

duanning9110
duanning9110 “数据选项可以包含形式为key1 = value1&key2 = value2的查询字符串,或者包含{key1:'value1',key2:'value2'}形式的对象
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐