Hello fellow developers,
I have a problem when printing PDFs that I've automatically generated with a Java application using iText 7. When I print such a PDF, the printout contains all pictures and graphics, but no text whatsoever.
Can someone tell me what the problem could possibly be? I've tried the "print as image" option in Adobe and came up with the same result.
Thank you very much.
EDIT/Added code and link:
Link to PDF file created this way
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();
答案 0 :(得分:0)
使用iText7对问题及其解决方案的简要说明:
表单字段窗口小部件的可见性(即,您将在查看器或打印中看到的表示)由一个无符号的32位整数控制,该整数存储在窗口小部件字典的/F
条目中。此条目是可选的,默认值为0。
整数被解释为一系列标志,其含义基于它们的位置,从低到高顺序。
位置3处的标志控制小部件的打印行为。如果设置为0,则永远不会打印小部件。
在iText7中,创建textField注释时,/F
条目不会自动添加到窗口小部件字典中,除非使用PdfTextFormField.setVisibility()
显式设置了值,因此此处的默认行为大致对应于VISIBLE_BUT_DO_NOT_PRINT
。
在7.0.2及更早版本中,可见和打印都没有关键字,但行为是作为PdfTextFormField.setVisibility()
的默认情况实现的,调用方法的任何数字,但1,2或3,将导致这种行为。 (1,2和3分别映射到HIDDEN
,VISIBLE_BUT_DO_NOT_PRINT
和HIDDEN_BUT_PRINTABLE
)。
在7.0.3(编写本报告时仍处于开发阶段)及之后,为方便起见,添加了关键字VISIBLE,以避免混淆。