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

Free Support Forum - aspose.com

Dynamically fill the Aspose PDF Form's expandable table

Hi,

I am trying to fill the PDF form’s table dynamically using the data from database. Since we do not know how many records are retrieved, thus we have to make the table and subForm “flow”. Also, in order to fill the cells of the table at runtime in JAVA, I create each cell to be “TextField” instead of “Text”. Then from JAVA, using setField to set each field.

However, only the first row is filled., the table does not seem to be expandable.

Please use the attached pdf file as input.

Thanks!

Hi Ying,

Can you please share the sample code with us so we could test the issue at our end? You’ll be updated accordingly.

We’re sorry for the inconvenience.
Regards,

I have attached the JAVA file and the resulting PDF here.

The main section to set the data in the form are:

for (int recordAssignedIndex = 1; recordAssignedIndex <= recordsAssigned
.size(); recordAssignedIndex++) {
dataValueAssigned = recordsAssigned
.get(recordAssignedIndex - 1).findField(fieldName);
form.setField(pdfFieldName + “.Row” + recordAssignedIndex
+ “[0].” + pdfTableColumnName + “[0]”,
dataValueAssigned.getLocalizedValue());
}

After setting the data, only the first row is filled.

If you have sample codes for dynamically setting the table content, it will be great.

Thank!

Hi Ying,

I have looked into the sample, however I would like to share that due to all the other code, it is very difficult to understand and reproduce this issue at our end. I would really appreciate if you could prepare a small working sample with the part under consideration. A working sample will help us reproduce the problem at our end and we’ll be able to help you out.

We’re sorry for the inconvenience and appreciate your cooperation.
Regards,

Hi,

Do you have any sample code that dynamically add the table row’s data in PDF file in JAVA? If so, would you please send it to me? At the mean while, I will try to write a standalone test project for you. I am in very tight schedule. Thanks for your understanding.

Regards,
-Ying

Hi Ying,

Currently, Aspose.Pdf.Kit for Java provides a class named AutoFiller which receives data from a database or XML, fills that data in predefined fields of the PDF form and then saves an output PDF file.

Please see the sample code on this link and share if it helps in your scenario. If it doesn’t satisfy your requirement or you have any further questions, please do let us know.

Regards,

Hi,

Sorry it takes very long for me to finally get my Aspose.Pdf.Kit license in order to continue working on this issue again.

Thanks for your suggestion, but I still could not find a good way to solve my problem.

Please find the attached file. I have created a dynamic table in this PDF file and I will get the data from the database to fill the table. Presume all field values are known, how could I use AutoFiller to fill the table each cell (note that the table is set to “flow”), and make it automatically grow depending on the number of records?

What is the format of the fieldNames vector? I would assume it represents all table column names (usually Table[Cell1], Table[Cell2}… etc.)

What is the format of the dataSource vector, each vector represent a single column values? how are these values separated for one single column?

Would you please provide a workable codes in JAVA?

Thanks,
-Ying

Hi Ying,

We’re looking into your requirement in detail at our end and you’ll be updated accordingly.

We’re sorry for the inconvenience.
Regards,

Hi Ying,

Please find a sample below to fill the fields using AutoFiller class:


// Auto filler example:


//column name is a vector of names of fields to fill

Vector columnName = new Vector();

columnName.add(“form1.emSubForm.emTable.Row1.Cell1”);

columnName.add(“form1.emSubForm.emTable.Row1.Cell2”);



//data source is a vector of vectors. Each of these vectors represents one row.

Vector dataSource = new Vector();


Vector row1 = new Vector();

row1.add(“John Smith”);

row1.add(“10.01.1970”);


Vector row2 = new Vector();

row2.add(“Bill Johnson”);

row2.add(“23.11.1965”);


dataSource.add(row1);

dataSource.add(row2);


String path = “d:\tmp\”;


AutoFiller autoFiller = new AutoFiller(columnName, dataSource);

autoFiller.setGenMultiPdfs(true);

//set input and output file names like this:

autoFiller.setBasicPath(path);

autoFiller.setBasicFileName(“output”);

autoFiller.setInputFile(“project_employee_moves.pdf”);

//set a field which will keep unflattened like this:

autoFiller.unFlatten(“Name”);

//fill data into the template like this:

autoFiller.importData();

//close the opened files and streams like this:

autoFiller.close();




This example show you how to fill the fields in an existing PDF file using AutoFiller class. You need to specify the field names in order to fill the data into a proper field. I’m sorry to inform you that it doesn’t support dynamic tables. However, if you want to create and fill rows dynamically, you can try creating the new fields at run time and then fill those fields. Also, note that, in the above example, if you set setGenMultiPdfs to true, then you can get multiple output files with same fields but different values for each row.

I hope this helps. If you have any further questions, please do let us know.
Regards,

Thanks for the sample code.

I need a way to create and fill rows dynamically for an existing table. I have tried to research on how to get the “table” object by name, but found no luck. I see examples that you can create a new table then add rows but not with the existing table.

Can you provide sample codes for obtaining the existing table object then add the rows to it and set the values into each cell?

This is very critical this is the only remaining issue for our current release, if you could provide a solution asap, it will be great!




Hi Ying,

Are you referring to the table created in the PDF file? If so, I’m sorry to inform you that it is not possible to create a new table using Aspose.Pdf.Kit; you can only create a new table and add rows, while creating a new PDF using Aspose.Pdf.

However, in your scenario, you can add new form fields at the specified locations (so, you can order them as rows and columns). Please try it at your end and see if that helps in your case or not.

We’re sorry for the inconvenience.
Regards,

Yes, the PDF file is predefine, within which, a dynamic table is also defined. The table full name is available.

Do you mean:

If I have an existing table, I can obtain the position for each cell of the first row and add the additional rows as needed? If so, how?

How I can decide if the row reaches the page break and add a new row in the next page?

Since this is the function used by many input PDF files, for different file, the table positions are different, it will only do if we somehow can find the table’s position by table name from PDF.

Is it possible?

Thanks!

Hi Ying,

I’m afraid, Aspose.Pdf.Kit doesn’t allow you to find an existing table or add new rows/cells in that table. What I meant was that you can place the controls, using the coordinates, at any location in the PDF page using Aspose.Pdf.Kit. Does that help in your scenario?

We’re sorry for the inconvenience.
Regards,




Oh, this is very surprising, since I understand that Aspose Word package can do the similar.

Do you know if there is any workaround to this problem? For example, if I have all the records stored into a XML file, will Aspose has the ability to import this xml file’s records and grow the table dynamically?

Thanks!

Hi Ying,

I’m sorry to inform you that this is not possible to fill a dynamically expandable form using Aspose.Pdf.Kit. However, the only workaround could be to create form fields dynamically, using your code, and filling the data. Please note that Aspose.Pdf.Kit can help you create and fill the individual fields, however the remaining logic to create fields dynamically would be in your own code.

We’re sorry for the inconvenience. If you have any further questions, please do let us know.
Regards,

Do you know if this functionality will be supported in near future? This is a key feature for our release. If not, we might have to search for other package that does.

Do you have a workaround for retrieving the “Table” object within PDF using the field name?

Thanks!

Hi Ying,

I have logged a new feature request as PDFKITJAVA-16242 in our issue tracking system. Our team will look into this requirement and you’ll be updated via this forum thread once it is supported in our future versions. However, I’m afraid this feature might not be supported in short time.

We’re sorry for the inconvenience.
Regards,

Hi Ying,

Can you please share whether you would like to add this dynamically expandable table in an existing PDF file or you want to create a new PDF file with such a table and data? If you want to create a new PDF with such a table, rows, columns and fields then you can use Aspose.Pdf.

Please share your thoughts.
Regards,



We need to add dynamically expandable table to existing PDF file.

We have many existing PDFs that need to be populate with ongoing data from the database server which contains tables.

Please update me with timeline that this feature will be availabel so that we can plan accordingly.

Thanks!

Hi Ying,

Thank you very much for sharing additional information.

As you know this feature request was logged recently and our team still needs to investigate it in detail, I’m afraid, I can’t share the ETA for this feature at the moment. However, I have asked our development team to share some idea once they’re clear about the requirement and the complexity involved. You’ll be updated once some response is received.

We’re sorry for the inconvenience and appreciate your patience.
Regards,