Copying TextField values from PDF

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v12)  /  Copying TextField values from PDF

DynamicPDF CoreSuite for .NET (v12) Forum

 Apr 11 2023 10:01 AM

I am using MergeDocument to add various FormElements to an existing PDF and am having difficulty copying values from a TextField after the final version of the PDF is generated/saved.

Ultimately I want to be able to set the PDF in read-only mode so that changes cannot be made to the TextField values after the PDF is generated, but this seems to prevent the user from selecting and copying the populated values when viewing the PDF in Acrobat or their browser.

I have been trying a combination of the properties below, but none of them seem to provide the functionality that I am looking for.  I have tried just setting pdf.Form.IsReadOnly without the Security added, but that still does not allow the user to select/copy a TextField value.

      pdf.Form.IsReadOnly = true;
      pdf.Security = new RC4128Security("")
        AllowFormFilling = false,
        AllowUpdateAnnotsAndFields = false,
        AllowEdit = false
 Apr 11 2023 10:51 AM
Posted by a ceTe Software moderator

If you would like to make the PDF non-edible but still allow users can select and copy the text, then please set only IsReadOnly property to true.

Here is a code sample:

            PdfDocument pdf = new PdfDocument(@"Source PDF path");
            MergeDocument document = new MergeDocument(pdf);
            document.Form.IsReadOnly = true;
            string outputPdf = @"C:\Temp\MyDocument.pdf";
If you continue facing an issue, then please send the following information to so we can look into it further.

1. Source PDF used for merging.
2. Output PDF.
3. Exact version and build number of DynamicPDF Core Suite for .NET product used in your application. You can find this information by right clicking on the DLL file>>Properties>>Details tab>>Product version. Take a screenshot of the Details tab and send it over to us.
4. Simple code sample used.

ceTe Software Support Team
I ended up solving the problem by setting pdf.Form.Output = FormOutput.Flatten

To address the previous comments by support...

pdf.Form.IsReadOnly = true; does not allow for the TextField value to be copied.

That being said, I noticed different behavior with the IsReadOnly flag across different PDF viewers.  When pdf.Form.IsReadOnly = true, FireFox browser and Slack PDF viewer allows for the form field value to be copied/selected.  Chrome/Edge/Adobe Acrobat DO NOT.

I am testing using CoreSuite version
Posted by a ceTe Software moderator

It is good to know that you have resolved this issue.

We tested this further and found that making PDF read-only using IsReadOnly property will not allow copying or editing the form field text (annotations).

Flattening the form is a good option to achieve your requirement.

Also please note that we are able to copy the Form field text by opening the output PDF in Adobe Reader.

ceTe Software Support Team

All times are US Eastern Standard time. The time now is 3:50 PM.