We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Pdf.kit for Java: setField doesnt work

Dear Sir/Mam,

I am trying your pdf kit for Java. I have loaded a pdf using the following code:

Form form = new Form( new ByteArrayInputStream(bytes), response.getOutputStream( ) );

bytes is the bytes of the pdf read from a file. I then say:

for ( String fieldName : form.getFieldsNames( ) ) {
form.setField( fieldName, “1234” );
}

I then close the form by saying form.close();

I should get the pdf with all the fields filled in with the text 1234 but I only see the original file with the input fields still being empty. It is as if the setField doesnt set the field value.

I have attached the pdf we use to fill.

Yours sincerly,
Martyn Hiemstra



This message was posted using Page2Forum (attachment) from Simple Example - Aspose.Pdf.Kit for .NET and Java

Hello Adam,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for considering Aspose.

If you need to fill the filed with some specific value, please use form.FillField. Before you call FillField method, make sure you are using the correct field name.

Both, the Field Name and Value are Case Sensitive.

For more information please visit How to Fill Form Fields With API?

Hi codewarior,

I have read the How to fill form fields with API. I forgot to mention that I am using the Java version.

I have tried the FillField method but it doesn’t exist. I’ve read the API docs and it doesnt contain any information about that method. I am using the com.aspose.pdf.kit.Form class.

Is this the right class or should I be using another Form class or possibly another class?

I have included the aspose.pdf.kit.jar and aspose.pdf.jar to my project. Are these 2 jar files enough to get the job done or am I missing a jar file?

Thanks,

Dear Hiemstra,

Thanks for considering our products.

Your code is correct. My colleague codewarior misunderstood your meaning. He thought you were using Aspose.Pdf.Kit for C#.

However, I am sorry to inform you that our products cannot support a document as you provided, neither C# version nor Java version. It used some advanced feature of Adobe called DataConnection. The fields in send.pdf is binded with specific contents in another document named data.xml.

In order to investigate into the problem, please provide the xml file(data.xml). We will decide whether to support this feature after that.

Sorry for the inconvenience & Best regards.

Hi Aspose,

Let me describe the solution we need. We want to design pdf’s in adobe lifecycle. We want to pre-fill the fields in the pdf with data from our database and export this filled pdf to the browser. We understand this can be done by using so called dataconnection binding but since this can only be done by the Adobe API this isn’t an option since the license cost is way too expensive. We would therefore like to create our own application that will merge the pdf with data from the database without using the dataconnection binding. Therefore I was looking into the setFields method. I want to put the information from the database into the fields using my own code and then output the pdf to the browser. It’s very important that the pdf is still editable when the client views the pdf in the browser so that the altered pdf can be printed.

Can your software supply such a solution?

Thanks,
Martyn Hiemstra

Hi Aspose,

I have discovered that the error was in my PDF. It contained databinding information that prefended data from being injected into the fields. I have created a new pdf without data binding and now it works perfectly.

I am looking further into your software and if it fulfills our needs, we will buy a license.

Thanks for your time and patience.
Martyn Hiemstra

Dear Hiemstra,

You are quite right. If you remove the data binding from the PDF template, our product will certainly work. FIY, you can also have a look at the AutoFiller class, which can fill fields with data from database automatically.

Please feel free to contact us if you still have any question.

Best regards.

Hi Aspose,

I am looking into your software, especially now that the other software I was testing has failed to meet our requirements.

I want to change the values of the fields, change the labels of certain fields and change the submit url of a button. I discovered that there is a Form and a FormEditor class. I found out that Form allows the changing of form values and the FormEditor object allows the changing of the submit url and field labels.

This makes pretty complex code because I have to load a pdf using the FormEditor and set the outputstream to a new ByteArrayOutputstream. Set the submit url and the labels. Then close the FormEditor. Use the ByteArrayOutputStream (whcih contains the altered pdf) and insert it into a Form object and then alter the field values and then close the Form. Is there 1 class that allows all the above actions instead of using two different classes and having to stream the pdf’s to and from different classes?

Thanks,
Martyn Hiemstra

Dear Hiemstra,

I am sorry to bring you into such complex use cases. But Form is designed to fill field with contents, while FormEditor is designed to change appearances or attributes of fields. Merging all functions into one singel class is feasible, however it requires user to generate a very huge object even he needs a simple function. For the sake of efficiency and stability, we decide to maintain two seperated classes.

Best regards.

Hi Aspose,

Thank you for your clear answer. Being a programmer myself I understand the choices made.

I will inform my boss that I want to buy a license to use your software because the evaluation of your software was very promising.

Thanks,
Martyn Hiemstra