Open
Description
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:
And this is how it was rendered in LibreOffice:
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.
Metadata
Metadata
Assignees
Labels
No labels
Activity