PDF field that is not Read Only is converted to read only after AutoFiller merge

Hello,

I’ve attached a PDF form and the output after merging, and my problem is on Page 4, near the bottom in the Daytime Phone Number area. I have a field there, “Master.OWNER_AREA_CODE” that is not Read Only in the template, but after merging, it behaves as a read only field.

Any idea why PDF.Kit would force this field to become read only?

Many thanks!

Mike

Hi,

Can you also provide us the source code that you used to get the output file. Basically we need to pin point the exact operation that causes this.

Thanks.

Hi Adeel,

Here's the code I'm using. Again, the problem occurs on Page 4 of the output PDF, where the Area Code field should be editable, but isn't.

protected void Button1_Click(object sender, EventArgs e)

{

DataTable testDT = new DataTable();

testDT.Columns.Add(new DataColumn("Master.OWNER_AREA_CODE", Type.GetType("System.String")));

testDT.Columns.Add(new DataColumn("Master.OWNER_PHONEWOAREA", Type.GetType("System.String")));

DataRow dr = testDT.NewRow();

dr["Master.OWNER_AREA_CODE"] = "303";

dr["Master.OWNER_PHONEWOAREA"] = "333-4444";

testDT.Rows.Add(dr);

AutoFiller autoFiller = new AutoFiller();

autoFiller.InputFileName = Server.MapPath("App_Data\\i-129.pdf");

Response.Expires = 0;

Response.Buffer = true;

Response.ClearContent();

Response.AddHeader("content-disposition", "inline; filename=" + "output.pdf");

Response.ContentType = "application/pdf";

autoFiller.OutputStream = Response.OutputStream;

autoFiller.ImportDataTable(testDT);

autoFiller.Save();

Response.End();

}

Hi,

I have been able to reproduce the error. I have logged this as PDFKITNET-4140 in our issue tracking system. We will try our best to resolve this issue as soon as possible.

Thanks.

Dear Mike,

For technical reasons, Autofiller will flattten filled fields by default. If you won't flatten some fields, their field names should be included in a class member named Autofiller.UnFlattenFields.

Please insert this line into your code and test again:

......

autoFiller.OutputStream = Response.OutputStream;

autoFiller.UnFlattenFields = new string[]{"Master.OWNER_AREA_CODE", "Master.OWNER_PHONEWOAREA"};

autoFiller.ImportDataTable(testDT);

......

Best regards.

Hi Luke,

Thanks for the message, and I’ve seen the method to Unflatten fields, but it won’t help me much because my application allows my users to supply their own templates and use their own data, so there’s no way I can pre-define which fields to unflatten.

Besides, what is so odd, is that all of the other fields in the example I provided work (as I desire), where fields not created as “read only” are editable.

Thanks for the suggestion though. I’m hopeful that an update will arrive soon that will address why the behavior apparently works for some fields, but not others.

Mike

Dear Mike,

I am some kind of confused by what you said "there's no way I can pre-define which fields to unflatten". If you want the output file to be editable, just including every field name in Autofiller.UnFlattenFields. However, if what you meant is that you cannot get their field names before hand, you also could do nothing to the document either, as well as AutoFiller.ImportDataTable() : as you already knows, these fieldnames should be defined into the DataTable first, which suggests that you have already known them, right :)

It is really strange that only "Master.OWNER_AREA_CODE" has been changed to be "read only". In fact, it was flattened. The output file (named as i-129_-_a0E50000000G4etEAC[4].pdf) seems not to be generated from the code you provide above (because I did not found any filling operations on other fields except for the two you mentioned in your sample code.) I really need and will appreciate your help to find out the bug. Please send me some more complete codes or your project if possible.

Best regards.

Hello Luke,

Many thanks for your patience in this discussion.

You’re absolutely right that of course I could set the AutoFiller.UnFlattenFields. I’ve tried doing that in the attached project so you can see what I’ve done. Although it works, it’s close to what I’d like to create, but not quite.

What I’m after is to be able to leverage features of the PDF Form itself, specifically, when creating the form fields (using Acrobat Professional or Nitro PDF), I’d like to set some fields to “Read Only” and leave other fields as editable, and as an extension of the field’s “read only” setting, I’m hoping that the “read only” fields get flattened and that the editable fields are not flattened.

What would really be great would be to iterate through the form fields on the PDF to find the ones that have the “read only” setting, and to set Autofiller.UnFlattenFields to those values. It doesn’t look like PDF.Kit can retrieve form field names and properties at this point – please correct me if I’m wrong.

Up to this point, PDF.Kit has worked the way I wanted, where “editable” fields are not flattened – at least that’s how my experience of the product has worked.

So if you think the best answer is to go ahead and set UnFlattenFields on all columns, by all means, that’s exactly what I’ll do… it’d be better if “read only” fields were flattened, but it would work.

I’m still puzzled though as to why, in the output from my sample project, on the fields on Page 4, one field is flattened, while the other isn’t. (When using the I-129.pdf file and not using UnFlattenFields).

(You were correct that the original output file I attached is not from the sample code, but the result is the same using the sample project.)

Anyway, I hope this is more clear now and I greatly appreciate your efforts and advice.

Denver Mike

Hey Luke,

If you wouldn’t mind preventing others from downloading the project, I would appreciate that too.

Dear Denver,

Only you and Aspose developers can download the attachment.

Dear Denver,

I would like to remind you of the following things

1. Actually Form.FieldsNames can retrieve all form field names from the PDF templates, but you cannot distinguish those "read only" fields from others till now. FYI, FormEditor.SetFieldAttribute can set a field to be ReadOnly.

2. A "ReadOnly" field is much different from a "Flattened" one. You can clear the "ReadOnly" flag to make a field interactive again, i.e., receiving user input and making response for it, but you have no way to do the thing with flattend field. So what you need is to FLATTEN those "ReadOnly" fields, right?

3. AutoFiller.UnFlattenFields contains those won't to be flattened, so you should EXCLUDE the read only ones other than "set Autofiller.UnFlattenFields to those values".

4. Please add the following code and test again:

autoFiller.Save();
Response.Flush();
Response.End();

A good news is that we are considering to provide an interface to return field's flag attribute, which can satisfy your requirement. Hope it helps.

Best regards.

Dear Denver,

I have downloaded the attachment. If you still worried about it, please remove it :) Perhaps I should give my email to you, sorry.

Best regards.

Very good, Luke. I will add the Response.Flush() to my code and check out the results.

You are absolutely right in #2 that what I desire is to flatten only the “ReadOnly” fields, so if PDF.Kit could identify field attributes so that I could discover the ones with the ReadOnly parameter, I would be in great shape.

Looking forward to hearing more on this.

Mike

I wanted to let you know that adding:

Response.Flush() where you indicated has corrected the problem. The Area Code field is now editable and not flattened, exactly as I was hoping.

Thanks again!

Dear Denver,

Fine. Furthermore, a new interface Form.GetFieldFlag( ) will be published in the new release, with which you can find out which fields are "ReadOnly". Please notice our blog and thanks for your patience.

Best regards.