В выводе говорится, что PDF поврежден или не удалось загрузить PDF. Как это исправить?
Что-то не так с блобом? Я проверил BLOB-объект, и он возвращает BLOB-объект: null / alphanumeri c
function ExportPDF(elem, filename='') {
var blob = new Blob([html], { type: 'application/pdf' } );
// Specify link url
var url = URL.createObjectURL(blob);
// // Specify file name
filename = filename ? filename + '.pdf' : 'document.pdf';
// // Create download link element
var downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
if (navigator.msSaveOrOpenBlob) {
navigator.msSaveOrOpenBlob(blob, filename);
} else {
// Create a link to the file
downloadLink.href = url;
// Setting the file name
downloadLink.download = filename;
//triggering the function
downloadLink.click();
}
document.body.removeChild(downloadLink);
}
<div id="export">
<text> 治験課題名 </text>
</div>
<button onclick="ExportPDF('export');">Export as PDF</button>