I am creating a duplicate of an existing TextField on another page of my pdf and i want the duplicate field to be readonly, so that the user can only change the value from the original field. Here is the section where i create the duplicate:
PdfPCell totalPriceCell = new PdfPCell()
{
BorderWidthLeft = 0,
BorderWidthRight = 0,
BorderWidthTop = 0,
BorderWidthBottom = 0f
};
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, false);
TextField tFieldTotalPrice = new TextField(writer, new iTextSharp.text.Rectangle(0, 0), dupTotalPriceName)
{
FieldName = dupTotalPriceName,
Alignment = 1,
FontSize = 12,
Font = bf
};
tFieldTotalPrice.SetRotationFromPage(doc.PageSize);
FieldPositioningEvents eventsTotalPrice = new FieldPositioningEvents(writer, tFieldTotalPrice.GetTextField());
PdfFormField fieldTotalPrice = tFieldTotalPrice.GetTextField();
fieldTotalPrice.SetFieldFlags(PdfFormField.FF_READ_ONLY);
fieldTotalPrice.SetFieldFlags(PdfFormField.FLAGS_READONLY);
//Divide row number by 2 and keep remainder. If remainder is 0, even. Else, odd.
totalPriceCell.BackgroundColor = r % 2 == 0 ? BaseColor.WHITE : new BaseColor(245, 245, 245);
totalPriceCell.CellEvent = eventsTotalPrice;
Setting the flags this way doesn't work, and it's the only solution i can find on similar questions thus far.
Thanks for your time!