2017-05-16 48 views
0

你好的开发伙伴们,无文本打印使用iText的创建7个

打印,我已经自动与利用iText 7. Java应用程序生成的PDF文件时,我有一个问题,当我打印这样的PDF PDF文件时,打印输出包含所有图片和图形,但不包含任何文字。

有人能告诉我问题可能是什么?我已经尝试了Adobe的“以图片形式打印”选项,并得出了相同的结果。

非常感谢。

编辑/添加的代码和链接:

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(); 
+5

请分享A)用于创建PDF的代码的关键部分B)重现问题的样例PDF。 –

+0

感谢您的回复,我在代码片段中添加了一个带有问题样本PDF的链接。 – Harry

+0

您是否检查过是否将Acrobat设置为打印表单域?要么是,要么你的文本区域的可见性都设置为可见,但不能打印。虽然,我不认为这是使用iText创建文本字段时的默认设置,并且您似乎没有设置您在此共享的代码... –

回答

0

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

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

在iText7,创建一个文本框标注的情况下,/F条目不会自动添加到窗口小部件字典,除非值被设定明确使用PdfTextFormField.setVisibility(),所以默认的行为在这里将大致与VISIBLE_BUT_DO_NOT_PRINT对应。

在7.0.2及更早的版本中,可见和打印都没有关键字,但其行为被实现为PdfTextFormField.setVisibility()的缺省情况,调用任何数字但1,2或3的方法将导致此行为。 (1,2和3分别映射到HIDDEN,VISIBLE_BUT_DO_NOT_PRINTHIDDEN_BUT_PRINTABLE)。

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