PDFsharp
PDFsharp copied to clipboard
Colors from a PdfTextField are not stored
I try to modify an existed PDF. The foreground and background should set to white. I iterate to all form elements and identify the right one. Then I cast it to PdfTextField. Then I assign BackColor and ForeColor but it will not be saved to the file. When I opened the new file the colors are not set.
string file = @"C:\temp\doc.pdf";
string file2 = @"C:\temp\output.pdf";
PdfDocument pdfDoc = PdfReader.Open(file, PdfDocumentOpenMode.Modify);
PdfAcroForm form = pdfDoc.AcroForm;
for (int i = 0; i < pdfDoc.AcroForm.Fields.Count; i++)
{
var item = pdfDoc.AcroForm.Fields[i];
string itemName = item.Name;
if (itemName == "Text1")
{
PdfTextField textField = (PdfTextField)item;
textField.BackColor = XColors.White;
textField.ForeColor = XColors.White;
}
}
pdfDoc.Save(file2);
pdfDoc.Close();
Changing the properties of a PdfTextField does not change the representation of this field in the PDF file. This is by design.
It is up to your code to change the representation of the field.
Okay, do you have an example how to update a representation?