Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Mar 19, 2018 12:57 pm

Hi Team,

One of our requirement is to add some hidden text (hash values) to pages or at document level so that end-users cannot remove/modify at any way. Once added we should be able to retrieve the same programmatically for some tracking.

Does SPIRE.PDF provides any mechanism to add custom data to PDF which is non-editable/removable and should be readable programmatically ? Kindly confirm.


Regards,
Raghavendran
TechMahindra LTD

RR00371658@Techmahindra.com
 
Posts: 4
Joined: Mon Feb 19, 2018 10:07 am

Tue Mar 20, 2018 8:08 am

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
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Thu Mar 22, 2018 10:50 am

Hi,

Thanks for the code snippet.
I am getting error during addition of metadata in line "doc.Form.Fields.Add(textbox);". This is because the form field is null.

Can you let me know how to add new form instance in-case PDF is not having one already?

Note: I am trying to do this for an existing PDF file.

Regards,
Raghavendran

RR00371658@Techmahindra.com
 
Posts: 4
Joined: Mon Feb 19, 2018 10:07 am

Fri Mar 23, 2018 1:43 am

Dear Raghavendran,

Thanks for your feedback.
Please add below code before creating a form field to an existing PDF file. In addition, my testing version is the latest Spire.PDF Pack(Hot Fix) Version:4.3.4
Code: Select all
doc.AllowCreateForm = (doc.Form == null) ? true : false;


Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Tue Mar 27, 2018 10:07 am

Hello,

Greetings from E-iceblue.
Did we resolve you issue?
Thanks for your valuable feedback and time.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Tue Mar 27, 2018 10:24 am

Hello Nina,

Yes, of course, it worked well. I was able to add the hidden values/read from PDF.

We are evaluating various products for our business needs, we will project the same to our team head. Based on various param final product yet to be decided.

I have recommended SPIRE.PDF based on my POC results.

Regards
Raghavendran

RR00371658@Techmahindra.com
 
Posts: 4
Joined: Mon Feb 19, 2018 10:07 am

Wed Mar 28, 2018 2:19 am

Dear Raghavendran,

Thanks for your feedback.
If you need further assistance, please feel free to contact us.
Have a nice day!

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF