How does Form.Save() work?


#1

Here's my code:

MemoryStream newMs = new MemoryStream();

Form newForm = new Form(Server.MapPath(".") + "\\TestForm.pdf", newMs);

newForm.FillField("EmpAddress", "5");

newForm.Save();

byte[] ba = newMs.GetBuffer();

HttpContext.Current.Response.Buffer = true;

HttpContext.Current.Response.Expires = 0;

HttpContext.Current.Response.ClearContent();

HttpContext.Current.Response.ContentType = "application/pdf";

HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=temp.pdf");

HttpContext.Current.Response.BinaryWrite(ba);

HttpContext.Current.Response.End();

When I run this, it populates the form fields correctly, and opens the PDF in the browser correctly. However, once the PDF is open, if I edit the value of the "EmpAddress" field in the browser, (change from '5' to '7' for example) close the browser, then re-run the code above, it opens the document again with '7' in EmpAddress, instead of the expect value '5' .

Why is this? Is this being cached somewhere? How can I fix it? (test document is attached)

I'm using Acrobat reader 7.0


#2

Dear timg,

Thanks for considering Aspose.

We are testing your pdf and will tell your the result ASAP.

Best regards.


#3

Dear timg,

I have tested your code and pdf. I found that your pdf can't be filled in the Adobe Reader 7.0.

A common pdf can't be filled in the Adobe Reader but only can be filled in Adobe Professional. Some IRS form can be filled by Adobe Reader. Please refer to this post.

So, you could only fill the form with our product in program or in the Adobe Professional. You could not fill it in Reader.

The function of translating the Adobe Professional only pdf form to Adobe Reader form will be supported in this month.

Best regards.


#4

I read the post you referred to, but I'm not sure if it really answered my question. I'm not having a problem filling the form or displaying it, and I don't need to be able to save it permanently. The problem occurs when I do the following:

1) Use pdf.kit form.FillField method to fill the field ( eg FillField("EmpAddress", "5") ) [works fine]

2) Display the filled form in a browser [works fine]

3) Use adobe reader to modify a value in one of the fields (eg, change "5" to "7") [works fine]

4) Close the browser [works fine]

5) Use pdf.kit to fill the same form with the original data (eg FillField("EmpAddress", "5") ) [broken]:

The pdf displays my modified data from step 3, instead of the value I inserted by using the .FillField method. That is, I do newForm.FillField("EmpAddress", "5"), so I expect to see a '5' when the form opens. Instead, I see a '7', which tells me that the value in the field is cached somewhere...it is keeping the value from the previous time the form was opened and modified.

Can you explain this?

Thanks.


#5

Dear timg,

Please read the next post. This post is deleted for some reason.


#6

Dear timg,

I have added your code into my demo project and found the problem.

It is the following line code which makes the difference :

HttpContext.Current.Response.ContentType = "application/pdf";

If this line is not in the program, the pdf will be opened correctly in the Reader independently even when the field is filled multi-times, otherwise, the pdf will be shown in IE as you said.

Perhaps it is the problem of IE's settings or the Reader's settings. I will study this and tell you the result. By the way, if you are experienced in this enviroment, please give some advices to me.

Best regards.


#7

You pointed me in the right direction...I found the problem. It is a setting in Adobe Reader. The way to change it (in Reader 7.0) is to click Edit>Preferences>Forms and then uncheck "Keep forms data temporarily available on disk"

This took care of the problem.

Thanks.


#8

Dear timg,

Congratulations for your resolving the problem.

Thanks for your sharing your experiences about this.

Best regards.