Hello,
Thanks for your inquiry.
Our Spire.Pdf can meet your need to hide some custom data in PDF, you could create a TexBox field and fill it with your custom data, followed by setting the TextBox to be invisible. After that, the data can be gotten programmatically as well. Below is sample code for your kind reference.
- Code: Select all
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();
PdfTextBoxField textbox = new PdfTextBoxField(page, "TextBox");
textbox.Bounds = new RectangleF(50, 50, 100, 15);
textbox.Text = "This is invisible text";
//Set the textbox to be invisible.
textbox.Visible = false;
doc.Form.Fields.Add(textbox);
doc.SaveToFile("InvisibleTextBox.pdf", FileFormat.PDF);
Get the data programmatically:
- Code: Select all
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("InvisibleTextBox.pdf");
PdfFormWidget widget = pdf.Form as PdfFormWidget;
for (int i = 0; i < widget.FieldsWidget.List.Count; i++)
{
PdfField f = widget.FieldsWidget.List[i] as PdfField;
if (f.Name == "TextBox")
{
PdfTextBoxFieldWidget textboxField = f as PdfTextBoxFieldWidget;
//Get the data
string text = textboxField.Text;
}
}
If there is any question, welcome to get it back to us.
Sincerely,
Nina
E-iceblue support team