jsPDF Acroforms无法在Angular应用程序中运行

问题描述 投票:0回答:1

我有一个Angular 7应用程序,我想用它生成一些使用jsPDF的PDF。我可以生成基于文本的PDF而没有任何问题,但是当我尝试添加Acroform字段时,生成PDF但字段丢失。以下是重现问题的步骤:

  1. 使用Angular-CLI创建一个新的Angular应用程序: 新的jspdfTester cd jspdfTester
  2. 安装jspdf npm install -s jspdf
  3. 将jspdf代码添加到app.component.ts文件中 import { Component } from '@angular/core'; import * as jsPDF from 'jspdf'; declare global { const TextField: any; } @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent { title = 'jspdfTester'; constructor() { const doc = new jsPDF(); const textField = new TextField(); textField.Rect = [50, 50, 30, 10]; doc.addField(textField); doc.text('test', 50, 40); doc.save('sample.pdf'); } }
  4. 运行应用程序,将下载包含测试文本但没有文本字段的PDF。

有想法该怎么解决这个吗?

编辑:经过仔细调试后,看起来像是调用了zone.js中的Object.getOwnPropertyDescriptor方法,而不是浏览器的Object.getOwnPropertyDescriptor方法。显然他们的工作方式不同,而且正在打破jsPDF。仍然没有解决方案,但我越来越近了。

angular jspdf
1个回答
0
投票

我发现zone.js会覆盖Object.defineProperty设置并更改jsPDF在定义AcroFrom原型时尝试设置的某些属性的配置值。我不确定是否可以在不更改两个库之一的情况下解决此问题。我有proposed a change to jsPDF所以也许在下一个版本中他们会解决它。

© www.soinside.com 2019 - 2024. All rights reserved.