Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentHandler - TOC improvement, investigation #1423

Open
OlofSvahnVbg opened this issue Oct 27, 2023 · 1 comment
Open

DocumentHandler - TOC improvement, investigation #1423

OlofSvahnVbg opened this issue Oct 27, 2023 · 1 comment
Labels
new feature Request for adding/changing functionality
Milestone

Comments

@OlofSvahnVbg
Copy link
Collaborator

So, I know this is old new probably. But the table of contents in document handler is really bad. So bad I wonder why we even have it. What information does this give the user:

image

There's no page reference or any other useful info, other than the sequence of chapters, which is (almost) pointless to know.

I talked to Jesper about adding to the TOC, and he, correctly - it would appear - said that it's really difficult to render a good TOC. And after googling a good bit, and asking chatgpt, and trying some of my own stuff, I can only agree. It's problematic.

I tried several approaches; generating a mock pdf and "measuring" the page contents. Did not work well.
I also tried selecting each element in the to be-printed document and trying to measure them, like this:

        printContent.querySelectorAll("p").forEach((element) => {
          if (element.childElementCount === 0) {
            totalHeight += element.offsetHeight;
            console.log(element.offsetHeight);
          }
        });

        printContent.querySelectorAll("h1").forEach((element) => {
          if (element) {
            totalHeight += element.offsetHeight;
          }
        });

        printContent.querySelectorAll("h2").forEach((element) => {
          if (element) {
            totalHeight += element.offsetHeight;
          }
        });

This, however, can possibly work, but for some reason the meausrements do not come out correct. Maybe something with what offsetHeight measures.

So, in conclusion, something should be done to improve the TOC. But! I don't know how. AND! I'm going on parental leave now, so if anyone sees this, I look forward to see it done and fixed when I come back. Thanks in advance.

@OlofSvahnVbg OlofSvahnVbg added the new feature Request for adding/changing functionality label Oct 27, 2023
@OlofSvahnVbg OlofSvahnVbg added this to the 3.x milestone Oct 27, 2023
@Hallbergs
Copy link
Member

You've done a thorough investigation, nice!

I agree that the TOC is completely useless in its current state. The reason it exists is that the customer who ordered the dh-print really wanted a TOC.

Let's hope that someone finds the strength to build a useful TOC while you are away!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Request for adding/changing functionality
Projects
Status: Approved ideas
Development

No branches or pull requests

2 participants