Welcome Guest Search | Active Topics | Sign In | Register

Flatten form field to appear as text with .NET PDF Options
Anita
Posted: Monday, July 13, 2015 9:19:50 PM
Rank: Newbie
Groups: Member

Joined: 7/13/2015
Posts: 1
Hi.

I am using EO.Pdf for .NET (C#). Using the library, I have successfully been able to read and modify existing PDF form fields changing the value of the field and setting the field to read-only, however I need to flatten it so when the PDF is saved it does not act as a field, but as normal text. How would I do this?

The code I'm using is based on a simple Windows form application that holds the folder path in a text box and a button that has the following Click event.

Code: C#
private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var folderpath = string.Format(@"{0}", textBoxFolder.Text);
                var sourcePdfName = "sample1.pdf";
                var targetPdfName = "demo1.pdf";
                var sourceFilename = string.Format("{0}{1}", folderpath, sourcePdfName);
                var targetFilename = string.Format("{0}{1}", folderpath, targetPdfName);

                var doc = new PdfDocument(sourceFilename);
                var fields = doc.Fields;
                
                var sb = new StringBuilder();
                sb.AppendLine("The following fields have been identified in the PDF document:");
                foreach (var field in fields)
                {
                    sb.AppendLine(string.Format("Field Name: {0}", field.Name));
                    //NameAddress
                    //CustomerName
                    //AccountNo

                    if (field.Name == "AccountNo")
                    {
                        field.Value = "####-####-####-4587";
                        field.ReadOnly = true;
                        // TODO: work out how to flatten the field so it appears like normal text when saved. Leave other fields enabled.
                    }
                }

                sb.AppendLine();
                sb.AppendLine(string.Format("New PDF created: {0}", targetPdfName));
                
                doc.Save(targetFilename);
                textboxOutputResults.Text = sb.ToString();
                
            }
            catch (Exception exception)
            {
               textboxOutputResults.Text = exception.Message;
            }
        }

I would appreciate any suggestions.

Thanks :)
eo_support
Posted: Tuesday, July 14, 2015 9:48:09 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
There is no way for you to do that in the current version. The closest you can get is to set the field's ReadOnly to true (which I see you are already doing). Sorry about it!
Ajay
Posted: Friday, January 29, 2016 11:57:33 AM
Rank: Newbie
Groups: Member

Joined: 1/12/2015
Posts: 1
Are there any plans in the near future to offer flattening options?
eo_support
Posted: Friday, January 29, 2016 12:43:51 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

We do plan to support this in the long run but have no plan to implement this in the immediate future.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.