Free Support Forum - aspose.com

Demo / example for performing a master/detail merge using AutoFiller?

Hello –

I think I saw some references somewhere on the Aspose site that you may have worked on how to perform a master/detail merge into a PDF form using AutoFiller, but I can’t find any details about it.

What I’m trying to accomplish is this: taking two DataTables (one with master data – customer details about an order, for example) and another DataTable with order line items. From the two data tables, I’d like to produce an invoice.

I suppose this assumes that the PDF form has a way to repeat line items (or maybe a table full of discrete fields).

Would the technique be to use the AutoFiller twice (once with each DataTable)?

Looking forward to your thoughts on how best to accomplish this (or even that it’s not really possible).

Mike

It would be great if I could use the same field naming conventions that are used in Aspose.Cells. Namely, in Cells, you can define a field as “&=TableName.FieldName”, and using that convention, it supports mutliple data tables.

That would be great if we could accomplish something similar with Pdf.Kit.

Dear Mike,

Thanks for considering our products.

I should admit that I don't catch your requirement very well. Did you mean that you want to fill one single PDF template twice by AutoFiller: first time with a "master" DataTable, and second time with a "detail" one? If my understanding is wrong, please provide an detailed example if possible.

Currently, AutoFiller.ImportDataTable(DataTable dataTable) can merge data from one DataTable into a well-predefined PDF template, one column for one suit of fields. If there are two DataTable needs to be imported, they can be handled one after another. However, the key point is that: they should be associated with different suits of fields.

Best regards.

Hi Luke,

Thanks for the message. Yes, I think you understood my requirement. To rephrase it, I’m trying to generate an Invoice document that has customer data at the top (name, address, etc), and the bottom will have many rows of line items (detail data).

The fields at the top of the PDF (name and address) come from one DataTable and should be easy to handle.

The challenge is how to handle the detail rows and from what you’ve said, it looks like I need to have many columns and rows of (discrete) PDF fields on the PDF. In other words, there’s no equivalent to a “Region” (in Aspose.Words) that would somehow automatically repeat rows of (detail) data.

The other challenge is whether after performing the first import from the DataTable, do the remaining PDF fields get “flattened”? If so, that will make performing a second import difficult. I’ll experiment with this, but I think you’ve already given me the direction I was looking for. Many thanks.

Dear Mike,

Basically, AutoFiller provides a mechnism to import data from a rather simple DB table to PDF template, one elements for one field. If you need some more complex scenario, perhaps you should make some efforts on your application.

As for your first challenge, I am wondering if some database operations will works. Suppose that you have two Tables, for example, CusomerTable and ItemTable. What is the relationship between them? Is there any way to create or merge them into a new table: AllTable to contain both data? If so, you can use AutoFiller.ImportDataTable(AllTable) to fullfill the requirement.

For your second challenge, you can set AutoFiller.UnFlattenFields to control which fields will not be flattened.

Best regards.