将URL网页导出为PDF格式的打字稿5

时间:2018-03-14 22:19:11

标签: javascript html angular typescript angular5

我正在尝试将网址导出为PDF。如下面的代码所示,solutionUrl是文章的链接。我希望能够在保存的pdf文件中看到该文章。现在它只显示pdf文件中的链接。



 component.st: 

 downloadPDF() {
    const doc = new jsPDF();
    doc.text(this.solutionUrl, 10, 10 );
    doc.save('Solution.pdf');
  }

component.html: 

  <button title="Export to PDF" (click)="downloadPDF()"> <i class="glyphicon glyphicon-file"></i></button>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我没有使用jsPDF,但这可能是因为doc.addHTML期望字符串作为参数,而不是URL。

另外,要以PDF格式显示HTML页面的内容,您需要使用this.http.get(url).subscribe(res => parseAndSaveToPDF(res)));方法

所以你的代码会像

一样流动
  1. 使用parseAndSaveToPDF
  2. 获取网址内容
  3. 然后定义body函数来解析网页内容并提取doc.addHTML(yourParsedBody)元素
  4. 最后使用$em->refresh($finalisation); 将正文值作为PDF格式。
  5. 这是另一个可能有用的SO answer

相关问题