How to Create PDFs With Node JS and React

How to Create PDFs With Node JS and React

JavaScript Mastery

5 лет назад

144,875 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Raymond Llavona
Raymond Llavona - 27.01.2019 00:52

Thank. You for the video. Is a nice code to implement in many applications

Ответить
Joshua Musau
Joshua Musau - 29.07.2023 06:21

Awesome!

Ответить
Abdikhaliq Mohamoud
Abdikhaliq Mohamoud - 18.07.2023 09:46

Anyone not comfortable with class components. This code may work:


import React, { useState } from 'react';
import axios from 'axios';
import { saveAs } from 'file-saver';

import './App.css';

const App = () => {
const [state, setState] = useState({
name: '',
receiptId: 0,
price1: 0,
price2: 0,
});

const handleChange = ({ target: { value, name } }) =>
setState((prevState) => ({ ...prevState, [name]: value }));

const createAndDownloadPdf = () => {
axios.post('/create-pdf', state)
.then(() => axios.get('fetch-pdf', { responseType: 'blob' }))
.then((res) => {
const pdfBlob = new Blob([res.data], { type: 'application/pdf' });

saveAs(pdfBlob, 'newPdf.pdf');
});
};

return (
<div className="App">
<input type="text" placeholder="Name" name="name" onChange={handleChange} />
<input type="number" placeholder="Receipt ID" name="receiptId" onChange={handleChange} />
<input type="number" placeholder="Price 1" name="price1" onChange={handleChange} />
<input type="number" placeholder="Price 2" name="price2" onChange={handleChange} />
<button onClick={createAndDownloadPdf}>Download PDF</button>
</div>
);
};

export default App;

Ответить
Shivaprasad
Shivaprasad - 22.04.2023 19:25

Can we use <script></script> inside the template string? will it work

Ответить
Jan michael Besinga
Jan michael Besinga - 14.01.2023 06:11

html-pdf is now deprecated.

Ответить
Anders Braathen
Anders Braathen - 03.01.2023 20:10

Thank you for the tutorial!

Ответить
SL CODEGEN
SL CODEGEN - 02.01.2023 10:07

Thank you

Ответить
Victor
Victor - 11.11.2022 09:36

ThankU

Ответить
Oranan Kumkhunthod
Oranan Kumkhunthod - 27.10.2022 10:20

How to custom font in PDF. 😅

Ответить
mohamed youssef
mohamed youssef - 01.10.2022 11:35

Awesome video +++++++++++++ 😃

Ответить
Jadeclon
Jadeclon - 02.09.2022 16:33

Why is flexbox not working in the template?

Ответить
Bikram Chettri
Bikram Chettri - 18.08.2022 04:25

Hey can you please update this tutorial?

Ответить
Pratik Shemare
Pratik Shemare - 06.07.2022 15:03

How to create template with Array of Objects? please reply...

Ответить
Latif James
Latif James - 01.07.2022 06:31

can you create a dropdown in html and save it as pdf with dropdown format included in the pdf. meaning when it save as pdf the dropdown still option on the pdf. i want to create a form that save from html to pdf with the bottom option have a dropdown for the manager to finish fill out

Ответить
Justin Nguyen
Justin Nguyen - 13.05.2022 09:53

I had to watch so many videos until I found you :) Thank you so much for the great video. This is perfect for all sorts of web applications!

Ответить
Dilshod Rahmatov
Dilshod Rahmatov - 01.04.2022 00:11

Can you update this tutorial? Thank you.

Ответить
D Israel
D Israel - 16.02.2022 11:36

It's awesome project but lack explanation line by line for beginners, also i get 404 error on console when trying to generate the PDF, if i can send you the code link for check would be really appreciated

Ответить
deadmoldable
deadmoldable - 26.01.2022 18:16

ok, but how to generate a pdf from react/jsx, not from html?

Ответить
gangaprasadk
gangaprasadk - 18.01.2022 18:45

Thanks for very helpful video. Can we use similar HTML templates to print any reports from ReactJS application. If so, can you make a video that shows how we store these templates in backend and then, based on the user choice, get a template into ReactJS application using a REST API and use it in printing a report. Thanks

Ответить
TechChunk
TechChunk - 15.01.2022 19:22

.then().then() was calling api's two time in my case so it was not working
So you can simply use async and await

Ответить
Yannapol Chatkaewmanewong
Yannapol Chatkaewmanewong - 11.01.2022 12:55

How to save to database help me please

Ответить
Cip: Massage Therapy
Cip: Massage Therapy - 04.01.2022 06:49

I'm just getting the error "__dirname is not defined" in my server console. The receipt is generated. Any solutions?

Ответить
Prashant Pandey
Prashant Pandey - 18.12.2021 11:25

Hi really nice video . Perfectly solves my problem . Just a question how to do multiple page pdf in it ? whatever HTML I am writing its generating single page PDF only. And if header and footer can be added for each page constant will be awesome

Ответить
Shahrukh M
Shahrukh M - 14.12.2021 13:12

Thank you,

Ответить
Viral vlogs
Viral vlogs - 21.10.2021 11:52

please make complete JS course from zero to hero

Ответить
Subhash G N
Subhash G N - 16.09.2021 11:59

very well explained.

Ответить
yash malviya
yash malviya - 26.08.2021 22:44

I have created my template but flex are not working

Ответить
Jahangir Alam
Jahangir Alam - 26.07.2021 09:04

how can I create pdf from React component ?

Ответить
Arpan Maji
Arpan Maji - 16.07.2021 15:08

how to delete the generated file in backend after download

Ответить
Enes GÜNGÖR
Enes GÜNGÖR - 12.07.2021 13:22

I have a HTML file and I want to convert it to pdf. I followed the video but my program doesnt work correctly . When I run HTML code separately it working very well but when I convert it to pdf it is crushing . Flexbox isnt work correctly . How can I fix that ?

Ответить
Paulo Tarcisio
Paulo Tarcisio - 21.06.2021 02:14

I try this:
pdf.create(html, { format: 'Letter' }).toFile('result.pdf', (err) => {
if (err) return res.status(500).send(err)
return res.status(200).send("ok")
})

but, it works only in my localhost environment.

When I hosted my application on Azure, this function never returns anything! And azure gives me this error message: "The page cannot be displayed because an internal server error has occurred.". It does not execute the line: " if (err) return res.status(500).send(err)"

I'm using, node 14.16.0, and my entire application works fine on Azure, only the html-pdf not works on it :(

Does anyone have any ideas?

Ответить
Vinit K
Vinit K - 11.06.2021 19:23

Wouldn't it be a better solution to convert react to pdf directly on frontend

Ответить
Nishant Kumar
Nishant Kumar - 18.05.2021 20:30

Thank you so much !!!

Ответить
Nathan Santos
Nathan Santos - 12.05.2021 18:30

I stopped watching when you copied and pasted the whole template html and css!

Ответить
Raihan Uddin
Raihan Uddin - 02.05.2021 04:16

Pls kindly help me how can use daynamic value in mongobd use pdf

Ответить
Raihan Uddin
Raihan Uddin - 22.04.2021 17:47

Pls any one help me how to use mongodb in pdf

Ответить
John Fazio
John Fazio - 26.03.2021 23:00

Great video, I subscribed

Ответить
שניאור בכר
שניאור בכר - 24.03.2021 22:35

thanks!!!!!!! How to display images using node.js server??? INTO INDEX.JS

Ответить
Thanish Ahamed
Thanish Ahamed - 26.02.2021 12:36

Cheers from Sri Lanka! Found the sollution with easy steps to use in my applications 🙂

Ответить
Animesh Timsina
Animesh Timsina - 25.02.2021 06:58

Thanks man! But I have some problems. Why aren't some css properties like flex supported?

Ответить
Biikaaa.
Biikaaa. - 28.01.2021 17:26

can i create doc files?

Ответить
Syedmujeeb H
Syedmujeeb H - 21.01.2021 08:12

Pls make a video on parsing pdf with streams buffers and chunks

Ответить
Rising Stars
Rising Stars - 29.12.2020 10:24

Thanks for great tutorial

Ответить
Daniel Presa
Daniel Presa - 21.12.2020 07:33

I don't know but, this tutorial is not right

Ответить
HanotzTv
HanotzTv - 17.12.2020 12:49

this is amazing video , do you have any suggestions about how to edit the number of products dynamically ?

Ответить
Tacitus Kilgore
Tacitus Kilgore - 11.12.2020 18:22

which theme do you use?

Ответить
Brainstorming AI
Brainstorming AI - 17.11.2020 16:26

Hi, I am able to create the entire pdf , (display grid and flex-box not working) just not getting the css styling from <style> tag.. Please help!

Ответить
Devansh Bhushan
Devansh Bhushan - 08.11.2020 14:03

Thanks a lot!! Your code helped me a lot!!

Ответить