Is it possible to build a completely dynamic table in the Generate Document from Template feature?

Using the .net server SDK and the “Generate Document from Template” feature, is it possible to build a completely dynamic table?

I have a use case where both my columns and rows would be dynamic.

Thanks!
-Brian

1 Like

Hello, I’m AiRon, an automated tech support bot :robot:
While you wait for one of our customer support representatives, I can help you with your question.


Yes, you can build a completely dynamic table using the “Generate Document from Template” feature in Apryse’s .NET Server SDK. This feature allows you to create tables where both the columns and rows can be dynamically generated based on your input data.

Some things you can try:

  • Design your template using an Office document (like a .docx file) where you define placeholders for your table structure.

  • Use JSON data to specify the dynamic content for your table, including both rows and columns.

  • Utilize the SDK’s support for loops and conditionals to manage the dynamic generation of table rows and columns.

  • Make sure your JSON data structure aligns with your template design to ensure correct data placement.



Here are some resources that might help you:


Hopefully, this helps you solve your problem while you wait for a human to get back to you.

1 Like

Hi Brian,

As our tech support bot indicated, I want to confirm that Apryse’s office template generation framework enables the dynamic generation of tables in documents. Take a look at our templated generation overview documentation here for more specific information and additional samples.

If you have any specific questions or issues regarding implementation of this functionality, please feel free to reach out!

Thanks,
Kaden Rettig
Technical Support Engineer
Apryse Support Team

1 Like

Thank you Kaden,

I saw the tech support bot response. However, I have yet to see an example or figure out on my own how to dynamically add columns to a table in a Word document (.docx) template.

Do you know if an example exists that may show how to dynamically add columns to a table in a Word document?

Or alternatively, do you know if the “Structured Input” definition for HTML or Markdown may be able to support Tables?

-Brian

1 Like

Hello Brian,

Apologies for the lack of response – I have been corresponding internally regarding your options for dynamic generation of table columns in addition to rows, as only the latter is currently covered in our documentation.

Although our Templating API does allow for the insertion of dynamic table content with rows & columns, called table_cells, it isn’t possible to format or resize the added cells & columns. This is why only the use of dynamic table_row generation is recommended. Apryse does offer another tool called Fluent, which allows for dynamic table generation and is more effective in this specific use case than the API offered currently by the Apryse SDK.

If you would like, I can create a feature request internally for the ability to effectively generate columns dynamically as is currently possible with rows in the Apryse SDK. However, I would ask that you provide specific examples of your desired use case, including the expected output, so that our Engineering team may better understand your requirements. Thank your understanding – please let me know if you have any additional questions.

Best,
Kaden Rettig
Technical Support Engineer
Apryse Support Team

1 Like

Thank you, Kaden.
I would be very interested in learning more about Fluent.
I would also be very interested in this feature being submitted as a feature request.

Attached are the sample documents I was working with
brian.docx (16.5 KB)
brian2.json (1.2 KB)
brian.json (3.4 KB)

The word document shows the table & merge tag syntax I was trying to use, as well as 2 examples of the desired outputs. The 2 json files show the 2 examples I was trying to work with.

Who could I speak with to learn more about Fluent and see a demo of a completely dynamic table structure.
-Brian

1 Like

Also - per your response, would it be possible to see an example of table_cells used in a .docx template? I didn’t see that feature in the online documentation I was reading.

thank you!
-Brian

1 Like

Brian,

Thank you for providing more information about your use case for this feature & your interest in Fluent as a potential solution. I will create a feature request internally regarding your interest in a solution that allows for dynamic column generation using the PDFNet SDK.

Would it be possible to see an example of table_cells used in a .docx template?

Regarding the use of the table_cells API, we do not currently offer any examples of its use on our website. However, you can still make use of it by doing the following:

  1. Create a table in a DOCX file
  2. Place {{some_tag}} in one of the cells
  3. In the template JSON, use: "some_tag": { "table_cells": [["a", "b"], ["c", "d"]] }

As the input only allows for the use of strings, you cannot format the text or the cells / rows / columns that it inserts. Our Engineering team has indicated that it is for this reason that table_cells is undocumented, as its current behavior is not customizable / adaptable for most use cases.

Who could I speak with to learn more about Fluent and see a demo of a completely dynamic table structure?

Our team would be happy to set up a demo / showcase so that you may consider the use of Fluent for your use case. However, so that we may ensure your request gets to the right team & update your contact information, I would ask that you fill out our Contact Sales form – once submitted, someone should reach out to you soon. If you have any other questions in the meantime, please don’t hesitate to ask.

Thank you,
Kaden Rettig
Technical Support Engineer
Apryse Support Team

1 Like

Thank you, Kaden.
I have reached out to our account manager for a discussion about Fluent.

In the meantime I have tried working with your table_cells feature.
Unfortunately I have not been able to get it to work.

Here are my sample files:
sample.json (86 Bytes)
sample1.docx (13.5 KB)
sample2.docx (13.5 KB)

sample.json is the JSON you provided in your response. A very simple payload of:

{ "some_tag": { "table_cells": [["a", "b"], ["c", "d"]] } }

sample1.docx
is a simple single cell table, testing to see if the Template API would build me the dynamic table that I am looking for.

result : I encounter the following exception

PDFNetException : pdftron.Common.PDFNetException: Exception:
         Message: Template error: Not enough table columns (1 available) to display autofill row content (2 required)
         Conditional expression: len <= num_cols
         Version      : 10.4.0-cae97e182c
         Platform     : Windows
         Architecture : AMD64
         Filename     : SimpleTableRow.cpp
         Function     : trn::Layout::SimpleTableRow::AutoFillRow
         Linenumber   : 171

sample2.docx
is a simple two cell table, trying to explicitly define the same number of columns in the docx template that the json payload contains.

result: My application crashes upon calling the FillTemplateJson method, providing the following error:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

For reference, in my test application I am using the NuGet package
PDFTron.NETCore.Windows.x64, version 10.4.0

I see that the latest version is 11.5.0, so I will update my test application to the latest release and try again, and I will post again shortly with updated results.

-Brian

1 Like

Unfortunately I encounter the same errors in both of my tests running version 11.5.0 of PDFTron.NETCore.Windows.x64

1 Like

Working with the Apryse team, I was able to implement a workaround to my variable column table structure.

In my case, there is a lower limit and upper limit to my table size, ranging anywhere from 3 to 10 columns. The idea was suggested to create 8 tables into the .docx template, 1 for each of the sizes, and then wrap each with an {{ if }} ... {{ endif }} condition. Then in my data file, where I need to render the table, I add attributes for:

"has_three_columns": false,
"has_four_columns": true,
"has_five_columns": false,
"has_six_columns": false,
...

so for the table that has four columns:
{{ if has_four_columns }} evaluates to true, and that table renders, while the other 7 tables are skipped because their {{ if }} condition evaluates to false.

it’s a bit heavy handed, but that’s the beauty of templating, I only need to build it once.

If it would help, I can post an example of what I’ve put together.

Now I’m running into my next problem - using insert_rows inside of a {{loop }} tag.
I don’t think it’s supported.

But I’ll post a separate ticket for that.

1 Like

Brian,

I am glad to hear that you were able to connect with a different team and successfully implement a column insertion method that works for your use case.

In regard to the specific use of insert_rows inside of a loop, it may not be necessary. You can use the loop with a structure containing any number of items to generate as many rows as needed, as seen below:

DOCX sample:
tg_demo_styled_table_loop.docx (381.2 KB)

JSON sample:
sample.json (194 Bytes)

Though I cannot verify whether it would be a perfect solution without your current implementation, please have a look and let me know if you have any further questions. Thank you for your patience!

Best,
Kaden Rettig
Technical Support Engineer
Apryse Support Team

1 Like