Reputation: 13
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.
Upvotes: 0
Views: 8361
Reputation: 4527
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);
//...
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.:
$('a#submit_link').click(function() {
// wrap links, etc. here
var html = $("body").html();
$('#hidden_form_input').val($html);
$('#hidden_form').submit();
});
Something like this should then present your user with the generated PDF.
Upvotes: 3