How to generate a PDF from a React component

  Рет қаралды 14,993

Cand Dev

Cand Dev

Күн бұрын

Пікірлер: 36
@GleristonCastro
@GleristonCastro Ай бұрын
I was exactly a few hours away planning to research this because I'm going to use it in a project I'm doing. And thank you for the video and also for your effort in making the video available in several languages. This will help a lot of people, you gained a subscriber.
@CandDev
@CandDev Ай бұрын
thank you 👋🏻
@iabhitech
@iabhitech Ай бұрын
Avoid directly creating pdf via image, unless there is only image, it will blur the pdf on zoom and text will be not selectable.
@CandDev
@CandDev Ай бұрын
you're absolutely right about the text not being selectable, but we can fix the blur by adjusting the scale. Thanks for the feedback
@abdarker
@abdarker Ай бұрын
exactly
@florianrichter4180
@florianrichter4180 Ай бұрын
i did it with Puppeteer. yes it's a bit more complicated but it works great and i have it OCR ready right away
@tiptrcks3960
@tiptrcks3960 29 күн бұрын
Bro why do even use that technique of embedding literally a screenshot to a pdf? Use react-pdf library for that purpose It provides components like view, text etc that renders to native pdf components that are not screenshots and are selectable, and copy able and you can use css to customize it as well(only limitation is you can't use grid) no formating issue whatsoever 😅
@shubhampawar7921
@shubhampawar7921 Ай бұрын
Or you could just write css to hide elements when printing and then "Generate PDF" button simply does Ctrl-P shortcut. This way you save installing/maintaining extra packages
@haiderjaafer8164
@haiderjaafer8164 Ай бұрын
Great lesson... Can make lesson on how to run reports in nextjs typescript... So can print reports example of jasper reports
@alitonoliveira1700
@alitonoliveira1700 26 күн бұрын
Dynamic graphs or charts would be awesome.
@CandDev
@CandDev 25 күн бұрын
great idea.
@iSoul95
@iSoul95 28 күн бұрын
Brilliant tutorial, thank you- Bytheway, the way you pronounce 'height' really confused me and I ended up scrolling back a couple of times the first time you explained what the 'w' and 'h' represented! The 'gh' is silent and isn't pronounced (Hite). Again, great stuff 💪
@CandDev
@CandDev 27 күн бұрын
thank you, Sorry about my pronunciation, my English isn’t perfect, but I’m working on it. Glad you found the tutorial helpful.
@iSoul95
@iSoul95 26 күн бұрын
@@CandDev No worries at all! Keep up the excellent work
@kimtoshi_444
@kimtoshi_444 Ай бұрын
Great knowledge 🎉❤
@pasindu0528
@pasindu0528 Ай бұрын
But in this case we must render the design if we need to convert several pages then how to handle it. all pages should render, are there any alternative solution
@CandDev
@CandDev Ай бұрын
for multi page pdf generation, you can create an array of page components: const pageComponents = [ , , ]; // generating PDF for (let i = 0; i < pageComponents.length; i++) { // Add a new page after the first page if (i > 0) { pdf.addPage(); } } but for more complex multi page pdf you can use react-pdf.
@ardianhotii
@ardianhotii 29 күн бұрын
@@CandDev great video thank you so much also can you please make a video using react-pdf to do this , like for example I want the header to be in all pages and the body of the pdf is too large so it can't fit in one page but has to continue in other pages with the same header and footer , please I would love that , if you do please reply here when you upload it if possible
@sashaBejenari
@sashaBejenari Ай бұрын
Thx! I have a weird bug. I have a form with inputs and the value from inputs are half hidden from bottom border of the inputs. I use shadcn.
@sanketgawande3667
@sanketgawande3667 Ай бұрын
The only problem with this approach is that the text is not selectable since it converts html content into canvas. If you need this for really serious stuff, go with puppetter package, create pdf on backend.
@CandDev
@CandDev Ай бұрын
you are right about the text issue. for professional pdf with selectable text, use Puppeteer or server-side PDF generation. These methods create better quality documents compared to image-based canvas conversion.
@simmslabs
@simmslabs 29 күн бұрын
Puppeteer is the best way. this approach changes the styles of some component. Even look at the header styles which doesnt sit well. Trust me ive been here before.
@bibarud3018
@bibarud3018 27 күн бұрын
Or simply, we can use the browser's native print API. It keeps the OCR.
@CandDev
@CandDev 27 күн бұрын
there's no right or wrong, it really depends on what you want to implement. Sometimes, users can't rely on the browser's native print API, so options like this are helpful.
@sadique_x_
@sadique_x_ 28 күн бұрын
please what's the terminal extension for suggestions you're using?
@CandDev
@CandDev 27 күн бұрын
i'm using iTerm with the zsh shell and the zsh-autosuggestions plugin for suggestions. It's super helpful
@sadique_x_
@sadique_x_ 27 күн бұрын
I appreciate you replying. thanks
@madmaxdev
@madmaxdev Ай бұрын
can we select the text of the pdf from that?
@ardhikaryzha317
@ardhikaryzha317 Ай бұрын
How to adjust a PDF paper to fit the content only?
@johnwyck9482
@johnwyck9482 Ай бұрын
great topic
@thomasjodt
@thomasjodt 28 күн бұрын
Is there a way to create a PDF that is not an image? I am currently needing a way to generate a PDF where people can select the text.
@CandDev
@CandDev 27 күн бұрын
You can check out my latest video about it here: kzbin.info/www/bejne/g4ereXqsgZiKopI
@OCEMTechZone
@OCEMTechZone Ай бұрын
Great🎉
@abdarker
@abdarker 29 күн бұрын
you said it's clean i can see the extra margin top inside the table Element, this is not the proper way. you gotta use react-pdf
@zeusek-2137
@zeusek-2137 28 күн бұрын
none of typescript was written in this video.
@princyworkspace
@princyworkspace 8 күн бұрын
It's an image in a pdf, unfortunatly it doesn't match all usecases
How to generate PDF in React using React pdf
15:35
Cand Dev
Рет қаралды 4,3 М.
How To Debug React Apps Like A Senior Developer
21:07
Web Dev Simplified
Рет қаралды 190 М.
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 908 М.
Introduction to Payload - The open-source Next.js backend
13:29
Generate a PDF in React
23:38
Colby Fayock
Рет қаралды 32 М.
How To Build a SAAS using Bolt.new (Use the LAPP Framework)
15:59
React 19: Новые хуки, которые вы ждали
21:13
Владилен Минин
Рет қаралды 16 М.
How to Prevent Browser Back Navigation | Next.js
7:55
Cand Dev
Рет қаралды 149
I Redesigned the ENTIRE YouTube UI from Scratch
19:10
Juxtopposed
Рет қаралды 1 МЛН
I Coded 10,000+ React Components, Here is What I Learned...
9:57