I am using html-pdf for pdf creation on my project. i can generate all the details into the pdf. but the thing is i can not be able to create List of items in array in html(which will be used for pdf conversion).
Since i cannot use javascript to get the array of items, i am unable to get it. if there is a tweak to use javascript in html template,please post it here. Since the array of items is known, i can use it easily.
Suppose if the array length is 3 . i can use like array[0].name ,array[1].name, array[2].name but here i don't know the length of the array which consists of how many items. Can anyone please help me here to generate the table of items which is generating dynamically.
Add a comment
|
1 Answer
You cannot use Javascript in template, but you can use Javascript on it.
The idea is to make a parser which will :
- read your template
- replace a keywork (for example :
<customTable arrayName="myCustomArray" fields="['name']" />) with a generated HTML array in Node.js. - use this template with html-parser.
I write an example of parser in VanillaJS here : https://jsfiddle.net/rbuuzcre/5/
2 Comments
codelearner
Thanks for your help, can you update fiddle with 4 columns in the table. please
F. Kauder
If you want to add columns, you just need to add some fields in array.