-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathreact-pdf.example.tsx
66 lines (62 loc) · 1.97 KB
/
react-pdf.example.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import ReactPDF from '@react-pdf/renderer'
import { renderJSONContentToReactPdf } from './react-pdf.js'
/**
* This example demonstrates how to render a JSON representation of a node to a React element
* It does so without including Prosemirror or Tiptap, it is the lightest possible way to render JSON content
* But, since it doesn't include Prosemirror or Tiptap, it cannot automatically render marks or nodes for you.
* If you need that, you should use the `renderToReactElement` from `@tiptap/static-renderer`
*
* You have complete control over the rendering process. And can replace how each Node/Mark is rendered.
*/
// eslint-disable-next-line no-console
const Element = renderJSONContentToReactPdf()({
content: {
type: 'doc',
content: [
{
type: 'heading',
content: [
{
type: 'text',
text: 'hello world',
marks: [],
},
],
attrs: { level: 2 },
},
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'hello world',
marks: [],
},
{
type: 'text',
text: 'hello world today is a test of this and of thathello world today is a test of this and of thathello world today is a test of this and of thathello world today is a test of this and of thathello world today is a test of this and of thathello world today is a test of this and of thathello world today is a test of this and of that',
marks: [],
},
{
type: 'text',
text: 'hello world',
marks: [],
},
{
type: 'text',
text: 'hello world',
marks: [],
},
{
type: 'text',
text: 'hello world',
marks: [],
},
],
attrs: { level: 2 },
},
],
attrs: {},
},
})
ReactPDF.render(Element as any, `${__dirname}/example.pdf`)