Skip to content

Commit 5fc0026

Browse files
committed
✨(frontend) add pdf outline property to enable bookmarks display
allows pdf viewers like adobe reader to display bookmarks in the sidebar Signed-off-by: Cyril <[email protected]>
1 parent dfd5dc1 commit 5fc0026

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ and this project adheres to
2222
- ♿(frontend) improve accessibility:
2323
- ✨ add document visible in list and openable via enter key #1365
2424

25+
### Changed
26+
27+
- ♿(frontend) improve accessibility:
28+
- ♿ add pdf outline property to enable bookmarks display #1368
29+
2530
## [3.7.0] - 2025-09-12
2631

2732
### Added

src/frontend/apps/impress/src/features/docs/doc-export/blocks-mapping/headingPDF.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,45 @@ import { Text } from '@react-pdf/renderer';
22

33
import { DocsExporterPDF } from '../types';
44

5+
// Helper function to extract plain text from block content
6+
function extractTextFromBlockContent(content: unknown[]): string {
7+
return content
8+
.map((item) => {
9+
if (
10+
typeof item === 'object' &&
11+
item !== null &&
12+
'type' in item &&
13+
'text' in item
14+
) {
15+
if (item.type === 'text' && typeof item.text === 'string') {
16+
return item.text;
17+
}
18+
}
19+
return '';
20+
})
21+
.join('')
22+
.trim();
23+
}
24+
525
export const blockMappingHeadingPDF: DocsExporterPDF['mappings']['blockMapping']['heading'] =
626
(block, exporter) => {
727
const PIXELS_PER_POINT = 0.75;
828
const MERGE_RATIO = 7.5;
929
const FONT_SIZE = 16;
1030
const fontSizeEM =
1131
block.props.level === 1 ? 2 : block.props.level === 2 ? 1.5 : 1.17;
32+
33+
// Extract plain text for bookmark title
34+
const bookmarkTitle =
35+
extractTextFromBlockContent(block.content) || 'Untitled';
36+
1237
return (
1338
<Text
1439
key={block.id}
40+
// @ts-expect-error: bookmark is supported by react-pdf but not typed
41+
bookmark={{
42+
title: bookmarkTitle,
43+
}}
1544
style={{
1645
fontSize: fontSizeEM * FONT_SIZE * PIXELS_PER_POINT,
1746
fontWeight: 700,

src/frontend/apps/impress/src/features/docs/doc-export/components/ModalExport.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
9898
exportDocument,
9999
)) as React.ReactElement<DocumentProps>;
100100

101-
// Inject language for screen reader support
101+
// Inject language for screen reader support and enable outlines (bookmarks)
102102
const pdfDocument = isValidElement(rawPdfDocument)
103-
? cloneElement(rawPdfDocument, { language: i18next.language })
103+
? cloneElement(rawPdfDocument, {
104+
language: i18next.language,
105+
pageMode: 'useOutlines',
106+
})
104107
: rawPdfDocument;
105108

106109
blobExport = await pdf(pdfDocument).toBlob();

0 commit comments

Comments
 (0)