How to generate an array of elements in an html template for creating pdf in Node Js?

I use html-pdf to create PDF files in my project. I can generate all the details in pdf. but I cannot create a list of elements in an array in html (which will be used to convert the PDF).
          Since I cannot use javascript to get an array of elements, I cannot get it. if it is possible to use javascript in the html template, submit it here. Since the array of elements is known, I can use it easily.
Suppose if the length of the array is 3. I can use how array[0].name ,array[1].name, array[2].name, but here I do not know the length of the array, which consists of the number of elements. Can someone help me here to generate a table of elements that is dynamically generated.

+4
source share
1 answer

You cannot use Javascript in a template, but you can use Javascript on it.

The idea is to make a parser that will:

  • read your template
  • replace the keyword (for example:) with the <customTable arrayName="myCustomArray" fields="['name']" />generated HTML array in Node.js.
  • use this template with html-parser.

I am writing an example parser in VanillaJS here: https://jsfiddle.net/rbuuzcre/5/

+2
source

Source: https://habr.com/ru/post/1649364/


All Articles