Flatten PDF and Executing embedded javascript

Hello good afternoon,

I contact to ask for your help to solve a question, I am a software developer and in the company we use other aspose products

We want to start a project where we have the need to flatten documents by removing the form fields from PDF files. I have a problem and that is that several documents have JavaScript embedded. We want JavaScript to make changes to some of the values in the fields of the PDF document and for these values to be rendered and displayed once the document is flattened.

I am trying to do it with the Document.Flatten method, this method flattens the fields but does not execute the JavaScript to assign the values to the fields before flattening the file. I have done tests with another library that does it but I was wondering if Aspose.PDF can do it since we have other projects where we use Aspose.PDF and we would like to handle the same interface.

Regards.

Jesus Gonzalez.

@jesusgonzalezr

Please try using FlattenSettings as following and in case issue still persists, please share your sample PDF document with some details on which values you need to be populated while flattening it. We will test the scenario in our environment and address it accordingly.

Form.FlattenSettings flattenSettings = new Form.FlattenSettings()
{
  CallEvents = true,
  HideButtons = false,
  UpdateAppearances = true
};
document.Flatten(flattenSettings);

@asad.ali

Thanks for your answer. Unfortunately for my case the code you sent me did not work.

I am attaching a pdf, I create it to exemplify the problem. The pdf has a Text field when you open it it is updated with the current date time (javascript code).

I would expect that after flatten the document I will see the current date in the new document, but instead the new document is generated with a previously saved static data (“08/18/2020 15:43:31”).

Date.pdf (17.0 KB)

Regards.

@jesusgonzalezr

We were able to notice the issue using Aspose.PDF for .NET 20.8 and logged it as PDFNET-48665 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.