1

我的要求是使用 Nodejs api 生成 UI(角度 4 应用程序)的 pdf 视图。为此,我从 UI 中获取了全部内容并进行了一些预处理,这些预处理将发送到 nodejs api。在节点 api 中,我使用html-pdf包从收到的 html 生成 pdf。能够生成具有正确样式的 pdf,因为它出现在 UI 中。以下是我的问题

  • 将整个 UI 内容(html、样式、引导 css)传递给 Node api 的安全方法是什么?(目前作为 POC 目的的普通字符串传递)
  • 我将如何将包生成的 pdf 流html-pdf返回到 UI 以在新选项卡上显示它

html-pdf包

来自角度的节点 api 调用:

  this.http.post('http://localhost:3000/api/createpdf', { 'arraybuff': data }, options)
        .catch(this.handleError)
        .subscribe(res => {

        })

当前数据是普通的 html 字符串,我通过在 node.js 中设置 body-parser 来检索它。

4

1 回答 1

0

我认为没有更好的方法将 HTML 传递给服务器,或者我可能不知道,但要在新选项卡中打开链接,请使用下面的代码

 this.http.post('http://localhost:3000/api/createpdf', { 'arraybuff': data }, options)
.catch(this.handleError)
.subscribe(res => {
       var blob = new Blob([(<any>res)], { type: 'application/pdf' });
       var url = window.URL.createObjectURL(blob);
       window.open(url);
})
于 2018-04-24T03:38:11.660 回答