Java 打印使用iText 7创建的PDF时没有文本

Java 打印使用iText 7创建的PDF时没有文本,java,pdf,adobe,itext7,Java,Pdf,Adobe,Itext7,各位开发者好 我在打印使用iText 7的Java应用程序自动生成的PDF时遇到问题。当我打印这样的PDF时,打印输出包含所有图片和图形,但没有任何文本 有人能告诉我可能是什么问题吗?我在Adobe中尝试了“打印为图像”选项,得到了相同的结果 多谢各位 编辑/添加代码和链接: 使用iText7简要说明问题及其解决方案: 表单字段小部件(即您将在查看器或打印中看到的表示)的可见性由存储在小部件字典的/F条目中的无符号32位整数控制。此条目是可选的,默认值为0。 整数被解释为一系列标志,其含义取决

各位开发者好

我在打印使用iText 7的Java应用程序自动生成的PDF时遇到问题。当我打印这样的PDF时,打印输出包含所有图片和图形,但没有任何文本

有人能告诉我可能是什么问题吗?我在Adobe中尝试了“打印为图像”选项,得到了相同的结果

多谢各位

编辑/添加代码和链接:


使用iText7简要说明问题及其解决方案:

表单字段小部件(即您将在查看器或打印中看到的表示)的可见性由存储在小部件字典的
/F
条目中的无符号32位整数控制。此条目是可选的,默认值为0。 整数被解释为一系列标志,其含义取决于它们的位置,从低到高。 位置3处的标志控制小部件的打印行为。如果将其设置为0,则永远不会打印小部件

在iText7中,创建文本字段注释时,
/F
条目不会自动添加到小部件字典中,除非使用
PdfTextFormField.setVisibility()
显式设置值,因此此处的默认行为大致对应于
可见,但不打印

在7.0.2及更早版本中,visible和print都没有关键字,但该行为是作为
PdfTextFormField.setVisibility()
的默认情况实现的,使用除1、2或3以外的任何数字调用该方法将导致此行为。(1、2和3分别映射到
隐藏
可见但不打印
隐藏但可打印


在7.0.3(撰写本文时仍在开发中)及以后版本中,为了方便起见,并避免混淆,添加了关键字VISIBLE。

请分享A)用于创建PDF的代码的关键部分B)复制该问题的PDF示例。感谢您的回复,我将代码片段添加到了一个带有该问题的示例PDF的链接。是否检查了是否将Acrobat设置为打印表单字段?或者您的文本字段都将其可见性设置为可见,但不打印。虽然,我不认为这是使用iText创建文本字段时的默认设置,而且您似乎没有在这里共享的代码中设置…@SamuelHuylebroeck,非常感谢。我必须设置所有字段
.setVisibility(0)没有可见的枚举,所以我假设这是标准行为-显然不是。@Harry在下一个版本中将有一个。我记得不久前在slackoverflow上遇到了一个类似的问题,并为它添加了一个枚举。仅供参考这里的数字0没有什么特别之处,其他可见性选项映射为1、2和3,并且方法中的默认开关语句设置为visible and print设置。
document = new Document(new PdfDocument(new PdfWriter(new FileOutputStream(dest))));        
this.form = PdfAcroForm.getAcroForm(document.getPdfDocument(), true);
PdfTextFormField fw1Field = PdfTextFormField.createText(document.getPdfDocument(),
                        new Rectangle(Variables.llx, Variables.lly, Variables.urx, Variables.ury), "Feld1");
fw1Field.setValue(fw1);
fw1Field.setReadOnly(Variables.readonly);
fw1Field.setBorderColor(Color.WHITE);
form.addField(fw1Field);

PdfTextFormField fsText = PdfTextFormField.createText(document.getPdfDocument(),
                        new Rectangle(Variables.llx + 150, Variables.lly, Variables.urx  + 50, Variables.ury), "FSText");
fsText.setValue("Freigabeschein:");
fsText.setBackgroundColor(Variables.backgroundColourText);
fsText.setBorderColor(Color.WHITE);
fsText.setReadOnly(Variables.readonlyText);
fsText.setBorderColor(Color.WHITE);
form.addField(fsText);

PdfTextFormField idField = PdfTextFormField.createText(document.getPdfDocument(),
                        new Rectangle(Variables.llx + 250, Variables.lly, Variables.urx, Variables.ury), "Freigabeschein Nummer");
idField.setValue(id);
idField.setReadOnly(Variables.readonly);
idField.setBorderColor(Color.WHITE);
form.addField(idField);

PdfTextFormField datumText = PdfTextFormField.createText(document.getPdfDocument(),
new Rectangle(Variables.llx + 350, Variables.lly, Variables.urx, Variables.ury), "DatumText");
datumText.setValue("Datum:");
datumText.setBackgroundColor(Variables.backgroundColourText);
datumText.setBorderColor(Color.WHITE);
datumText.setReadOnly(Variables.readonlyText);
form.addField(datumText);

//more Text, created exactly as above

PdfButtonFormField buttonSpeichern = PdfFormField.createPushButton(document.getPdfDocument(), new Rectangle(450, 20, 100, 30), "speichern", "SPEICHERN");
buttonSpeichern.setBackgroundColor(Color.LIGHT_GRAY);
buttonSpeichern.setValue("Speichern");
buttonSpeichern.setVisibility(PdfFormField.VISIBLE_BUT_DOES_NOT_PRINT);
buttonSpeichern.setAdditionalAction(PdfName.D, PdfAction.createJavaScript("saveFSFunction(1);"));
form.addField(buttonSpeichern);

PdfButtonFormField buttonDrucken = PdfFormField.createPushButton(document.getPdfDocument(), new Rectangle(300, 20, 100, 30), "drucken", "DRUCKEN");
buttonDrucken.setBackgroundColor(Color.LIGHT_GRAY);
buttonDrucken.setValue("Drucken");                                             
buttonDrucken.setVisibility(PdfFormField.VISIBLE_BUT_DOES_NOT_PRINT);
buttonDrucken.setAdditionalAction(PdfName.D, PdfAction.createJavaScript("printFunction(1, 0, 1, \"FS\");"));
form.addField(buttonDrucken);

document.close();