crimson589
crimson589

Reputation: 1308

iText creating readonly textfield on existing pdf

Here's my setup, I have an existing PDF file which I want to add fields to. I'm successfully adding the fields and setting up the options but if I add the READ_ONLY option to the field i lose my MULTILINE option. It keeps the font size though to whatever i set it to. I've also tried putting the READ_ONLY option before setting other options.

ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfReader reader = new PdfReader("PDF PATH");
PdfStamper stamper;
stamper = new PdfStamper(reader, baos);
AcroFields fields = stamper.getAcroFields();

TextField textField = new TextField(stamper.getWriter(), new Rectangle(18, 200, 380, 278), "newTextField");
textField.setOptions(TextField.MULTILINE);
textField.setFontSize(0f);
textField.setText("VERY LONG TEXT");
//textField.setOptions(TextField.READ_ONLY); If I add this option my textfield is no longer multiline
stamper.addAnnotation(textField.getTextField(), 1);

stamper.close();

Upvotes: 1

Views: 1889

Answers (1)

Mạnh Quyết Nguyễn
Mạnh Quyết Nguyễn

Reputation: 18235

Because when you call the setOptions() again, the internal value will be overrided.

If you want to use both feature, you must combine the options and save all at once:

textField.setOptions(TextField.MULTILINE | TextField.READ_ONLY);

Upvotes: 3

Related Questions