When download DOMPDF using jquery ajax in WordPress php.The pdf downloaded but page its blank.
below code file is generatepdf.php
test.php
Generate PDF
$(document).ready(function() {
$('#generatePdfButton').click(function() {
// Make an AJAX request to generate.php
$.ajax({
url: 'generatepdf.php',
type: 'GET',
success: function(response) {
// Handle success
var blob = new Blob([response], { type: 'application/pdf' });
var url = window.URL.createObjectURL(blob);
var link = document.createElement('a');
link.href = url;
link.download = 'test.pdf';
link.click();
window.URL.revokeObjectURL(url);
},
error: function(xhr, status, error) {
console.error('Failed to generate PDF:', error);
// Optionally, display an error message to the user
}
});
});
});
Generate PDF
I want to render html properly when call jquery ajax to download pdf.