首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jsPDF文档中的可编辑字段不打印

jsPDF文档中的可编辑字段不打印
EN

Stack Overflow用户
提问于 2016-06-02 12:50:13
回答 2查看 1.5K关注 0票数 2

我已经创建了一个可编辑字段的pdf文档,使用jsPDF。一切看起来都很好,但是当我打印它时,字段值不包括在内。这是一些用于测试它的示例代码(来自jsPDF/examples/js/AcroForm.js):

代码语言:javascript
复制
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文件,它识别字段,但不会打印内容。

EN

回答 2

Stack Overflow用户

发布于 2022-08-28 09:04:12

您可以使用AcroFormTextField。

代码语言:javascript
复制
  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);
票数 0
EN

Stack Overflow用户

发布于 2022-08-28 13:50:14

执行部分的问题是版本1。

此外,核心问题是可以独立设置用于显示和打印的AcroField外观,因此该字段显示,但不能在Acrobat或类似的查看器中打印。

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

代码语言:javascript
复制
<!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>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37592377

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档