I am working to achieve the function for user to generate their trip plan into a pdf that they can carry around with them. react-pdf is a very powerful tool for me to achieve this goal.
Prevent SSR in Next.js
As the web rendering functions of react-pdf only work on client side, the first problem I faced was to prevent server side rendering. I wrote another blog on this issue.
Code for a nice pdf
So here comes the big part: create a nice pdf for user’s trip plan. There are limited options on what components I could use:
Page
Link
Text
View
Image
Note
Canvas It is to be noted that View can be nested within another View.
Creat a fixed header that appears on each page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import { Text, View, Link } from '@react-pdf/renderer';