java PDF-Form 文本隐藏除非单击

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12198742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 08:00:34  来源:igfitidea点击:

PDF-Form Text hidden unless clicked

javapdfpdf-generationpdfboxpdf-form

提问by codejitsu

In my application I have to fill a predefined PDF form with data from DB. We are using Java and Pdfbox. The filling itself is not a problem.

在我的应用程序中,我必须使用 DB 中的数据填写预定义的 PDF 表单。我们正在使用 Java 和 Pdfbox。填充本身不是问题。

The problem is that in resulting PDF-file all texts in the form are invisible (or hidden, also grey rectangles) unless field clicked.

问题是在生成的 PDF 文件中,除非单击字段,否则表单中的所有文本都是不可见的(或隐藏的,也是灰色的矩形)。

How can I solve this problem?

我怎么解决这个问题?

回答by dirkk

I had the same problem when I tried to programmatically fill PDF forms using pdfbox. I add this answer to a rather old question as all the other answers manipulate the original PDF, which is not always an option.

当我尝试使用 pdfbox 以编程方式填写 PDF 表单时,我遇到了同样的问题。我将此答案添加到一个相当古老的问题中,因为所有其他答案都操纵原始 PDF,这并不总是一个选项。

The problem with invisible form fields just appeared in Acrobat PDF, other PDF renderers showed it fine. If using pdfbox 1.8.x you have to set Need Appearancesas explained here:

不可见表单域的问题刚刚出现在 Acrobat PDF 中,其他 PDF 渲染器显示它很好。如果使用 pdfbox 1.8.x,您必须Need Appearances按照此处的说明进行设置:

PDAcroForm form = docCatalog.getAcroForm();
form.getDictionary().setItem(COSName.getPDFName("NeedAppearances"), COSBoolean.TRUE);

If using pdfbox 2 this is simplified to:

如果使用 pdfbox 2,则简化为:

PDAcroForm form = docCatalog.getAcroForm();
form.setNeedAppearances(true);

回答by Zalia

I read this on a forum and worked for me:

我在论坛上读到了这个并对我来说有效:

Using Adobe Acrobat Pro, I exported the form using "Export Data" to a XML and then imported it back from XML-file with "Import Data". Those commands are under Forms/Manage Forms Data

使用 Adob​​e Acrobat Pro,我使用“导出数据”将表单导出为 XML,然后使用“导入数据”将其从 XML 文件中导入回来。这些命令在 Forms/Manage Forms Data 下

This is the link to the post: http://forums.adobe.com/thread/637421

这是帖子的链接:http: //forums.adobe.com/thread/637421

回答by g-eorge

I had this exact problem with a form I was filling with PDFBox in Java.

我在用 Java 中的 PDFBox 填写表单时遇到了这个确切的问题。

I fixed it by opening the original (blank) PDF form in Acrobat Pro and changing some options for each of the problem text fields. The options might vary for you, but here's what worked for me:

我通过在 Acrobat Pro 中打开原始(空白)PDF 表单并更改每个问题文本字段的一些选项来修复它。您的选择可能会有所不同,但以下是对我有用的方法:

In the Acrobat Pro menu bar go to Forms > Add or edit fields. Right click the text field in Acrobat Pro and select properties, then:

在 Acrobat Pro 菜单栏中,转至表单 > 添加或编辑字段。在 Acrobat Pro 中右键单击文本字段并选择属性,然后:

In the 'Options' tab:

在“选项”选项卡中:

  • Untick all options except 'scroll long text'
  • Add a few space characters in to the Default Value box
  • 取消勾选除“滚动长文本”以外的所有选项
  • 在默认值框中添加几个空格字符

In the 'Appearance' tab:

在“外观”选项卡中:

  • Set the font size to 'auto'
  • 将字体大小设置为“自动”

Click 'close form editing' and save the file.

单击“关闭表单编辑”并保存文件。

Field Options

字段选项

回答by BoBFiSh

I don't quite know how you can stop it happening in the future but a resolution to getting the file working, similar to g-eorge is to open it in adobe acrobat pro, in tools on the right hand menu select "Interactive objects" and choose select object.

我不太清楚你将来如何阻止它发生,但是让文件工作的解决方案,类似于 g-eorge 是在 adobe acrobat pro 中打开它,在右侧菜单上的工具中选择“交互式对象”并选择选择对象。

When you highlight the first field you want to fix, you should then be able to control-a to select all interactive objects. Once all are selected, right click on one field and select properties.

当您突出显示要修复的第一个字段时,您应该能够使用 control-a 选择所有交互式对象。全部选中后,右键单击一个字段并选择属性。

In the "general" tab the bottom option should have "common properties" which has the option "form field" change this to hiddenand then back to visible. This will then restore all visibility to the form.

在“常规”选项卡中,底部选项应具有“通用属性”,其中“表单字段”选项将其更改为隐藏,然后返回可见。这将恢复表单的所有可见性。

This has worked for me on all the rare instances when I receive this, and hasn't failed me once. Hope it does the same for you,

当我收到此消息时,这在所有罕见的情况下都对我有用,并且一次也没让我失望。希望它对你也一样

BoB

鲍勃

回答by adamold

in the appearance tab of each erroneously hidden object you will see the "fill color" set to none. set it to none again (just click on it) and save the PDF and these fields will show up normally. I can't believe adobe has let this error persist for so long. It happens constantly when viewing/saving with multiple pdf readers.

在每个错误隐藏的对象的外观选项卡中,您将看到“填充颜色”设置为无。再次将其设置为无(只需单击它)并保存 PDF,这些字段将正常显示。我不敢相信 adobe 已经让这个错误持续了这么久。使用多个 pdf 阅读器查看/保存时,它会不断发生。

回答by Susie

I just ran across this and tried a combination of things before one very simple thing worked. I have Adobe Acrobat 9.0 and I couldn't find some of the options written here.

在一个非常简单的事情奏效之前,我刚刚遇到了这个问题并尝试了一些事情的组合。我有 Adob​​e Acrobat 9.0,但我找不到这里写的一些选项。

What I ended up doing was a two-pronged process: I went to Forms > Manage Form Data > Export Data; I then saved that file on my desktop. Next, I went back to Forms > Manage Form Data but instead selected Import Data, and selected that file I'd just saved. Bingo! Everything filled in properly.

我最终做的是一个两管齐下的过程:我去Forms > Manage Form Data > Export Data;然后我将该文件保存在我的桌面上。接下来,我返回到 Forms > Manage Form Data 而是选择了Import Data,并选择了我刚刚保存的那个文件。答对了!一切都填妥了。

回答by nevster

Nothing I tried here worked - except to change software.

我在这里尝试的任何方法都不起作用 - 除了更改软件。

I was using PDFElement 6 Pro (trial) and couldn't make it work. Tried all sorts of things with PDFBox plus all suggestions above.

我正在使用 PDFElement 6 Pro(试用版)但无法使其工作。使用 PDFBox 以及上述所有建议尝试了各种方法。

Ended up trying https://www.pdfescape.com/and it all worked just fine.

最终尝试https://www.pdfescape.com/并且一切正常。