[英]PDF of current form should be created on clicking a link using jquery
I want to save my current page in PDF format on clicking a link. 我想在单击链接时以PDF格式保存当前页面。
My html code 我的html代码
<a id="pdf" href="javascript:void(0)">
Download PDF
</a>
I tried this code but it is not working 我尝试了此代码,但无法正常工作
require_once('dompdf_config.inc.php'); //on including this i get a blank page
script in same page 同一页面中的脚本
<script type="text/javascript">
$(document).ready(function(){
$("#pdf").click(function(){
var html = $("body").html();
$.post( "d1.php",{ data: html});
});
});
</script>
d1.php contains d1.php包含
<?php
$html = $_POST['data'];
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("myCV.pdf");
?>
please help me in fixing it.Suggest me if there is any better solution. 请帮助我修复它。如果有更好的解决方案,建议我。
Thanks in advance 提前致谢
The file inclusion.. 文件包含..
require_once('dompdf_config.inc.php');
...actually belongs at the top of d1.php. ...实际上属于d1.php的顶部。 Also, in d1.php, you have the line:
另外,在d1.php中,您需要执行以下操作:
$html = urldecode($_POST['html']);
However, you don't have any form fields named "html" so I'm not sure how you're getting that data to post to that file. 但是,您没有任何名为“ html”的表单字段,因此我不确定如何将这些数据发布到该文件中。 And, you have a hidden form field with the id of "#hidden_form", but you seem to be intending to call the submit() function on the form, which has no id attribute.
并且,您有一个ID为“ #hidden_form”的隐藏表单字段,但是您似乎打算在不具有id属性的表单上调用commit()函数。 You should add an id attribute to the form with the value of "hidden_form" (no #) if you wish to call the function this way.
如果您希望以这种方式调用函数,则应在表单中添加一个id属性,其值为“ hidden_form”(无#)。
This doesn't seem to be the most efficient way to do what you're wanting, but I believe if you start with these things, you'll be getting closer to where you want to be. 这似乎并不是完成您想要的事情的最有效方法,但是我相信,如果您从这些事情着手,您将越来越接近您想要的地方。 Once those are done, if you still have problems, turn on the error reporting as mentioned above.
完成这些操作后,如果仍然有问题,请如上所述打开错误报告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.