我正在制作一个使用数据库中的值生成的动态 html 页面。用户可以选择“隐藏”div 并操作页面上的其他元素。我想将页面上的所有 HTML 发送到 DOMPDF 并让它为我生成下载链接。
<a href="dl.php">Download</a>
其中 dl.php 会有类似这样的内容,其中 html 被发送到 DOMPDF 并生成:
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("myCV.pdf");
但是,由于用户正在操作页面上的 DOM 并且我想删除链接之类的东西,所以我使用 jquery 来获取 html
$('a').wrap('<span style="display:none;"></span>');
var fullhtml = $("#body").html();
fullhtml = encodeURIComponent(fullhtml);
annnndd因为它是一个大页面,我不能使用GET,必须使用POST来发送html。我如何获得它,以便我可以使用 html 对 dl.php 进行 AJAX 调用,然后“包含”该页面以便它运行?如果我从 AJAX 调用返回任何内容,pdf 文件就会转换为文本,这会是一团糟。
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>
Where dl.php would have something like this where the html is sent to DOMPDF and generated:
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("myCV.pdf");
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 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.
发布评论
评论(1)
我不确定我是否完全理解您的问题,但据我了解,您正在获取页面的 HTML,隐藏所有链接,然后将 POST 请求中的整个内容提交到 dl.php ,对吧?所以 dl.php 会说这样的话:
对吗?
您可以让用户通过单击链接来启动此过程,此时您
可以 在提交之前使用隐藏的输入和经过处理的 HTML(隐藏的链接等)填充表单,即:用户使用生成的 PDF。
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? Sodl.php
would say something like this:Right?
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.:
Something like this should then present your user with the generated PDF.