3

我正在从 HTML 生成 PDF,并且在我的本地计算机上运行良好,该计算机具有 Windows 作为操作系统。但是现在我将我的应用程序部署在 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);
});
4

0 回答 0