我终于找到了一个可以打开和阅读xfa表单的lib(pdf.js)。但是我无法填写字段、保存它们并下载新的 pdf。 有人有关于如何做到这一点的例子吗? 谢
试图找到一些例子,但没有成功。
代码草案:
const pdfDocument = 等待 pdfjs.getDocument({ ...来源, 启用Xfa:真, }).承诺;
if (pdfDocument.allXfaHtml) {
setFormType('xfa');
setInputs(getAllInputs(pdfDocument.allXfaHtml));
setOutput(JSON.stringify(pdfDocument.allXfaHtml, null, 2));
pdfDocument.annotationStorage.setValue('FamilyName23412', { textContent: 'Test Surname' });
pdfDocument.annotationStorage.setValue('GivenName23413', { textContent: 'TestName' });
pdfDocument.annotationStorage.setValue('FamilyName23412', { value: 'Test Surname' });
pdfDocument.annotationStorage.setValue('GivenName23413', { value: 'TestName' });
pdfDocument.saveDocument();
const pdfBlob = new Blob([await pdfDocument.getData()], { type: 'application/pdf' });
const pdfUrl = URL.createObjectURL(pdfBlob);
const downloadLink = document.createElement('a');
downloadLink.href = pdfUrl;
downloadLink.download = 'downloaded.pdf'; // Specify the desired filename
// Automatically trigger the download by simulating a click
downloadLink.style.display = 'none'; // Hide the link
document.body.appendChild(downloadLink);
downloadLink.click();
URL.revokeObjectURL(pdfUrl);
}