我已经创建了一个可编辑字段的pdf文档,使用jsPDF。一切看起来都很好,但是当我打印它时,字段值不包括在内。这是一些用于测试它的示例代码(来自jsPDF/examples/js/AcroForm.js):
var doc = new jsPDF();
doc.text(10, 65, 'TextField:');
var textField = new TextField();
textField.Rect = [50, 50, 120, 80];
textField.multiline = true;
textField.V = "The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse";
textField.T = "TestTextBox";
doc.addField(textField);
doc.save('Test.pdf');我需要做一些其他的事情才能打印字段文本吗?我在Acrobat中打开了生成的pdf文件,它识别字段,但不会打印内容。
发布于 2022-08-28 09:04:12
您可以使用AcroFormTextField。
var doc = new jsPDF();
doc.text(10, 65, 'TextField:');
var textField = new AcroFormTextField();
textField.Rect = [300, 150, 120, 80];
textField.multiline = true;
textField.V = "The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse";
textField.T = "TestTextBox";
doc.addField(textField);发布于 2022-08-28 13:50:14
执行部分的问题是版本1。
此外,核心问题是可以独立设置用于显示和打印的AcroField外观,因此该字段显示,但不能在Acrobat或类似的查看器中打印。

版本2的语法已经改变,但是textField.showWhenPrinted有一个设置,可以是= true或= false,但是默认值应该是true。

<!DOCTYPE html>
<html lang="en">
<head>
<!-- use latest cdnjs 2.5.1 version or the min(imised) variant -->.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.js" integrity="sha512-Bw9Zj8x4giJb3OmlMiMaGbNrFr0ERD2f9jL3en5FmcTXLhkI+fKyXVeyGyxKMIl1RfgcCBDprJJt4JvlglEb3A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body>
<script>
// for version 2 standalone include
window.jsPDF = window.jspdf.jsPDF;
/* global jsPDF */
var doc = new jsPDF();
// note the new name changes
var {TextField} = jsPDF.AcroForm;
doc.text(10, 10, 'Hello Field$');
doc.text('A TextField:', 10, 85);
var textField = new TextField();
//Here is the critical one since field appearence can be on/off for screen and or print
textField.showWhenPrinted = true;
textField.Rect = [50, 50, 120, 80];
textField.fontSize = 25;
textField.multiline = true;
textField.value = "The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse"; //
textField.fieldName = "TestTextBox";
doc.addField(textField);
doc.save('Test.pdf');
</script>
</body>
</html>

https://stackoverflow.com/questions/37592377
复制相似问题