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

PageReference is only rendered in LibreOffice #2904

Open
rfsalman opened this issue Dec 18, 2024 · 0 comments
Open

PageReference is only rendered in LibreOffice #2904

rfsalman opened this issue Dec 18, 2024 · 0 comments

Comments

@rfsalman
Copy link

rfsalman commented Dec 18, 2024

Issue

  • PageReference is only rendered in LibreOffice

Environment

  • Docxjs version: 8.5.0

Description

I am trying to create a Table Of Contents manually because TableOfContent was not displaying anything, by keeping a reference to headers and render then with InternalHyperlink.

Below is the simplified version of the code:

const headers = [
  { id: 'mainheaders1', text: '1. General' },
]

const borders = {};

const rows = [];

const linkText = new TextRun({
  text: headers[0].text,
  style: 'headerLinkText',
});

const link = new InternalHyperlink({
  anchor: id,
  children: [linkText],
});

const pageNumber = new Paragraph({
  alignment: 'end',
  style: 'headerLinkText',
  children: [new TextRun(' '), new PageReference(id, { hyperlink: true })], // ! PageReference is not working on most docx editors, only in LibreOffice
});

 const row = new TableRow({
  children: [
    new TableCell({
      margins: {
        top: 120,
        bottom: 120,
      },
      borders,
      width: {
        size: 70,
        type: WidthType.PERCENTAGE,
      },
      children: [
        new Paragraph({
          children: [link],
        }),
      ],
    }),
    new TableCell({
      margins: {
        top: 120,
        left: 240,
      },
      borders,
      width: {
        size: 30,
        type: WidthType.PERCENTAGE,
      },
      children: [pageNumber],
    }),
  ],
});

rows.push(row);

const contentsTable = new Table({
  margins: {
    left: 0,
    top: 0,
    right: 0,
    bottom: 0,
  },
  borders,
  width: {
    size: 100,
    type: WidthType.PERCENTAGE,
  },
  rows,
});

const section: ISectionOptions = {
  properties: {
    type: SectionType.NEXT_PAGE,
  },
  children: [pageHeader, contentsTable],
};

Opened in Microsoft Word, this is how the document was rendered:
toc

And this is how it was rendered in LibreOffice:
toc-libre

The hyperlinks work in all editors, but i'd like the PageReferences to work on all editors too, are there any special handling required for specific editors ?

Big thanks to the maintainers of this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant