Skip to content

Commit 65a3137

Browse files
committed
♻️(front) improve table pdf rendering
The previous way of rendering table was causing issues when tables could not fit on one page. I then came accross this discussion diegomura/react-pdf#2343. The author created a lib to improve the rendering of table, it's better, but still not perfect maybe.
1 parent 5cc4b07 commit 65a3137

File tree

4 files changed

+14714
-14666
lines changed

4 files changed

+14714
-14666
lines changed

src/frontend/apps/impress/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"test:watch": "jest --watch"
1616
},
1717
"dependencies": {
18+
"@ag-media/react-pdf-table": "2.0.1",
1819
"@blocknote/core": "0.23.2",
1920
"@blocknote/mantine": "0.23.2",
2021
"@blocknote/react": "0.23.2",

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import { Doc } from '@/features/docs/doc-management';
2727
import { TemplatesOrdering, useTemplates } from '../api/useTemplates';
2828
import { downloadFile, exportResolveFileUrl } from '../utils';
2929

30+
import { Table } from './blocks/Table';
31+
3032
enum DocDownloadFormat {
3133
PDF = 'pdf',
3234
DOCX = 'docx',
@@ -151,6 +153,9 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
151153
</Text>
152154
);
153155
},
156+
table: (block, t) => {
157+
return <Table data={block.content} transformer={t} />;
158+
},
154159
},
155160
},
156161
{
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { TD, TH, TR, Table as TablePDF } from '@ag-media/react-pdf-table';
2+
import {
3+
DefaultBlockSchema,
4+
Exporter,
5+
InlineContentSchema,
6+
StyleSchema,
7+
TableContent,
8+
} from '@blocknote/core';
9+
import { View } from '@react-pdf/renderer';
10+
import { ReactNode } from 'react';
11+
12+
export const Table = (props: {
13+
data: TableContent<InlineContentSchema>;
14+
transformer: Exporter<
15+
DefaultBlockSchema,
16+
InlineContentSchema,
17+
StyleSchema,
18+
unknown,
19+
unknown,
20+
unknown,
21+
unknown
22+
>;
23+
}) => {
24+
return (
25+
<TablePDF>
26+
{props.data.rows.map((row, index) => {
27+
if (index === 0) {
28+
return (
29+
<TH key={index}>
30+
{row.cells.map((cell, index) => {
31+
return (
32+
<TD key={index}>
33+
{props.transformer.transformInlineContent(cell)}
34+
</TD>
35+
);
36+
})}
37+
</TH>
38+
);
39+
}
40+
return (
41+
<TR key={index}>
42+
{row.cells.map((cell, index) => {
43+
return (
44+
<TD key={index}>
45+
<View>
46+
{
47+
props.transformer.transformInlineContent(
48+
cell,
49+
) as ReactNode
50+
}
51+
</View>
52+
</TD>
53+
);
54+
})}
55+
</TR>
56+
);
57+
})}
58+
</TablePDF>
59+
);
60+
};

0 commit comments

Comments
 (0)