Replies: 1 comment
-
The issue you're encountering — where the text field content is only visible on focus — is typically caused by a missing or improperly generated appearance stream ( SolutionTo fix this, you need to ensure that OpenPDF generates the appearance stream when setting the field value. Here's a working code example: PdfReader reader = new PdfReader(template);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, baos);
AcroFields form = stamper.getAcroFields();
form.setGenerateAppearances(true); // Important to regenerate appearance
// Set field value
form.setField(fieldName, value);
// Optional: flatten the form if you don't need it to be editable
// stamper.setFormFlattening(true);
stamper.close();
reader.close(); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Using OpenPdf 1.4.2 I have a class which places TextField areas on a pdf (as a byte array). I am using that as a template and have another class to produce another pdf with the TextField populated.
Text field definition.
TextField tf = new TextField( writer, new com.lowagie.text.Rectangle(llXPt, llYPt, llXPt + widthPt, llYPt + heightPt), fieldName);
template is the incoming byte array
(PdfReader pdfReader = new PdfReader(template)) PdfStamper stamper = new PdfStamper(pdfReader, <byte array output>);
AcroFields form = stamper.getAcroFields(); form.setGenerateAppearances(true);
form.setField(fieldName, value);
No matter what I try, the resultant Pdf when opened only displays the content in the text field when I click on it. Soon as the field loses focus, text is not visible.
Can anyone help please? What else do you need to know?
Beta Was this translation helpful? Give feedback.
All reactions