我正在从HTML生成PDF,并且在我的本地计算机(Windows操作系统为OS)上运行良好。但是现在,我将应用程序部署在Linux服务器上,该服务器提供了如下奇怪的输出。 。
服务器端代码(节点)
const htmlPdf = require('html-pdf')
try{
let html = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /></head><body><div>Managed APs</div><br /><table><th>AP Serial</th><th>AP Name</th><th>AP Model</th><th>Mac Address</th><th>IP</th><th>Connect Status</th><th>Cluster</th><tr><td>1010212112</td><td >AP_Test</td><td>RJ147</td><td>1.23.2.2</td><td>1.23.12.4</td><td>Connected</td><td>Dummy Cluster</td></tr></table></body></html>`
htmlPdf.create(html).toBuffer(function(err, buffer){
if(err){
return res.json({
success: false,
message: dbErrorMessage
});
} else{
const pdfData = buffer.toString('base64')
return res.json({
success: true,
data: pdfData
});
}
});
}
catch(e){
return res.json({
success: false,
message: e
});
}
客户端代码(Angular5)
base64ToArrayBuffer(base64) {
const binaryString = window.atob(base64);
const binaryLen = binaryString.length;
let bytes = new Uint8Array(binaryLen);
for (let i = 0; i < binaryLen; i++) {
let ascii = binaryString.charCodeAt(i);
bytes[i] = ascii;
}
return bytes;
}
const view = this
view.apiData.downloadFileService().subscribe(res => {
const response = res.data;
$('#overlay').hide();
const fileData = view.base64ToArrayBuffer(response);
let a = document.createElement("a");
document.body.appendChild(a);
let file = new Blob([fileData], { type: 'application/pdf' });
const url = window.URL.createObjectURL(file);
a.style.display = 'none';
a.href = url;
a.download = 'aps';
a.click();
window.URL.revokeObjectURL(url);
});