It not works very well. I mixed the stuff for testing reasons in my test environment in a non linear way.
I really hate to bug you guys, but I find this topic kind of exciting. I would like to get the TOC somehow dynamic. The most suitable way is to read the header directly from DOM, preferably without additional function calls in the html source code. Can i call the pdfAddPageItem
function directly via script from my template? Or can deal with the rendered dom in the script section (under the html sourcecode)?
So, I want to parse the finished DOM outside the template and pass the found elements to the function pdfAddPageItem
purely script based (not via handlebars). But somehow I can't get to the html source of the finished DOM.
The HMTL DOM is correct. The remixed order in the DOM looks like this:
1. Heading (main)
1.1. Heading (main)
3. Heading (child)
3.1. Heading (child)
3.2. Heading (child)
4. Heading (child-child)
4.1. Heading (child-child)
5. Heading (child-child)
5.1. Heading (child-child)
5.1.1. Heading (child-child)
5.2. Heading (child-child)
1.1.1. Heading (main)
1.2. Heading (main)
1.2.1. Heading (main)
2. Heading (main)
2.1. Heading (main)
2.2. Heading (main)
2.3. Heading (main)
3. Heading (child)
3.1. Heading (child)
3.2. Heading (child)
4. Heading (child-child)
4.1. Heading (child-child)
5. Heading (child-child)
5.1. Heading (child-child)
5.1.1. Heading (child-child)
5.2. Heading (child-child)
With a little hassle I get the pdf TOC mapped with the function pdfAddPageItem
and my little helper function pdfAddTocItem
.
Yes ok that looks a bit weird:
"laterToc": [
{ "title": "1. Heading", "parent": "root", "id": "h-1" },
{ "title": "1.1. Heading", "parent": "h-1", "id": "h-1-1" },
{ "title": "1.1.1. Heading", "parent": "h-1-1", "id": "h-1-1-1" },
{ "title": "1.2. Heading", "parent": "h-1", "id": "h-1-2" },
{ "title": "1.2.1. Heading", "parent": "h-1-2", "id": "h-1-2-1" },
{ "title": "2. Heading", "parent": "root", "id": "h-2" },
{ "title": "2.1. Heading", "parent": "h-2", "id": "h-2-1" },
{ "title": "2.2. Heading", "parent": "h-2", "id": "h-2-2" },
{ "title": "2.3. Heading", "parent": "h-2", "id": "h-2-3" },
{ "title": "3. Heading", "parent": "h-1-1", "id": "noh-3" },
{ "title": "3.1. Heading", "parent": "noh-3", "id": "nonoh-3" },
{ "title": "3.2. Heading", "parent": "noh-3", "id": "noh-3-2" },
{ "title": "3. Heading", "parent": "root", "id": "yesh-3" },
{ "title": "3.1. Heading", "parent": "yesh-3", "id": "yesyesh-3" },
{ "title": "3.2. Heading", "parent": "yesh-3", "id": "yesh-3-2" },
{ "title": "4. Heading", "parent": "h-1-1", "id": "abcnoh-4" },
{ "title": "4.1. Heading", "parent": "abcnoh-4", "id": "abcnoh-4-1" },
{ "title": "5. Heading", "parent": "h-1-1", "id": "abcnoh-5" },
{ "title": "5.1. Heading", "parent": "abcnoh-5", "id": "abcnoh-5-1" },
{ "title": "5.1.1. Heading", "parent": "abcnoh-5-1", "id": "abcnoh-5-1-1" },
{ "title": "5.2. Heading", "parent": "abcnoh-5", "id": "abcnoh-5-2" },
{ "title": "4. Heading", "parent": "root", "id": "abcyesh-4" },
{ "title": "4.1. Heading", "parent": "abcyesh-4", "id": "abcyesh-4-1" },
{ "title": "5. Heading", "parent": "root", "id": "abcyesh-5" },
{ "title": "5.1. Heading", "parent": "abcyesh-5", "id": "abcyesh-5-1" },
{ "title": "5.1.1. Heading","parent": "abcyesh-5-1","id": "abcyesh-5-1-1"},
{ "title": "5.2. Heading", "parent": "abcyesh-5", "id": "abcyesh-5-2" }
]
Or should I make the work and try to program a possible extension on nodejs level?