You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Timo Rumland <ti...@digitalys.de> on 2016/05/08 21:25:27 UTC

PDF form: Strange behavior with filled out textfield (only visible after clicking the field)

Hello,

I'm trying to fill out a PDF form with PDFBox 2.0.0 (using Java 6). My test
PDF file is a really simple PDF form, containing only one text label and one
text field named "textfield01". When I run my code to fill out that single
form field with the string "test", no error occurs.

Opening the saved file with Acrobat Reader DC, the text field contains the
string "test".

But opening the saved file with PDF XChange Viewer (2.5), which is what our
clients use, I have the following problem:

First, the text field is empty. Strangely, after clicking into that text
field, the string "test" appears. After losing the focus, the text
disappears. When I then edit the contents of the text field and the text
field loses focus, the text remains visible (all with using PDF XChange
Viewer).


If you may, you can download my Test-PDF form file here:
https://goo.gl/y03zht


Please, see this simple example code, which shows how I fill the textfield:

----

PDDocument pdDocument = PDDocument.load( new File(
"g:/2016-05-08_test-form.pdf" ) );

PDDocumentCatalog pdDocumentCatalog = pdDocument.getDocumentCatalog();
PDAcroForm pdAcroForm = pdDocumentCatalog.getAcroForm();

String pdFieldName = "textfield01";

PDField pdField = pdAcroForm.getField( pdFieldName );
if ( pdField == null )
    throw new RuntimeException( "Failed to fill PDF field: Given field '" +
pdFieldName + "' is unknown" );

pdField.setValue( "test" );

File file = new File( "g:/test-form_out.pdf" );
FileOutputStream fileOutputStream = new FileOutputStream( file );

pdDocument.save( fileOutputStream );
pdDocument.close();

fileOutputStream.close();

----


I don't think this is a bug with PDFBox. Maybe I do something wrong or the
PDF XChange Viewer has some strange behavior. Whatever the cause is, I
really need to be able to safely fill out a PDF form which values then must
be visible within that PDF viewer.


As a side note: I create the PDF form by creating a file with LibreOffice
Writer, insert a text field and export it via PDF. Maybe that PDF file has a
"problem"? Unfortunately I have no knowledge about the PDF specification to
decide if hat may be the case.



I really appreciate any help you can offer


Thanks a lot!


Best regards,
Timo Rumland


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org