制作下载链接DOMPDF生成的PDF同一页面上
我正在从数据库中的值动态生成HTML页面。用户必须隐藏的div和操作页面上的其他元素的选项。我要发送的页面,DOMPDF上的所有HTML和有它生成一个下载链接给我。
I'm making a dynamic html page generated with values from a database. The user has the option to "hide" divs and manipulate other elements on the page. I want to send all the HTML on the page to DOMPDF and have it generate a download link for me.
<a href="dl.php">Download</a>
在哪里dl.php将有这样的事情,其中的HTML被送到DOMPDF和产生的:
Where dl.php would have something like this where the html is sent to DOMPDF and generated:
$ DOMPDF =新DOMPDF();
$ dompdf-&GT; load_html($ HTML);
$ dompdf-&GT;渲染();
$ dompdf-&GT;流(myCV.pdf);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("myCV.pdf");
然而,由于用户操作页面上的DOM,我想,我使用jQuery抢HTML摆脱这样的东西联系
However since the user is manipulating the DOM on the page and I want to get rid of stuff like links, I'm using jquery to grab the html
$('a').wrap('<span style="display:none;"></span>');
var fullhtml = $("#body").html();
fullhtml = encodeURIComponent(fullhtml);
annnndd因为它是一个大的页面,我不能使用GET,必须使用POST发送的HTML。我将如何得到它,这样我可以做一个AJAX调用与HTML到dl.php,只是'包括',这样它运行的页面?如果我从一个AJAX调用返回任何内容,PDF文件被转换成文本是一个烂摊子。
annnndd since it's a large page, I can't use GET, have to use POST to send the html. How would I get it so that I can just do a AJAX call with the html to dl.php and just 'include' the page so that it runs? If I return anything from a AJAX call, the pdf file gets converted into text which is a mess.
我不知道我理解你的问题正是,但据我了解,你正在做网页的HTML,隐藏所有的联系,然后提交POST请求里面整件事 dl.php
,对不对?因此, dl.php
会说这样的事情:
I'm not sure I understand your question exactly, but as far as I understand, you're taking the HTML of the page, hiding all the links, and then submitting the whole thing inside a POST request to dl.php
, right? So dl.php
would say something like this:
$html = urldecode($_POST['html']);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
//...
右?
您可以让用户通过点击一个链接,在这一点上,你有一个隐藏的输入与处理的HTML填充表单启动这个过程中(隐藏链接等)提交发生之前,即:
You could have the user initiate this process by clicking a link, at which point you populate a form with a hidden input with the processed HTML (links hidden, etc.) before the submission takes place, i.e.:
$('a#submit_link').click(function() {
// wrap links, etc. here
var html = $("body").html();
$('#hidden_form_input').val($html);
$('#hidden_form').submit();
});
这样的事情应该那么present您与生成的PDF用户。
Something like this should then present your user with the generated PDF.