![]() ![]() ![]() In order for this to work, too, we're adding an async keyword just before our function definition up above. Notice that here, we expect that function to return us a JavaScript Promise, so we add the await keyword in front to say "wait for the Promise returned by this function to resolve before continuing with the rest of our code." Next, using the puppeteer package we imported up top, we create an instance of a web browser with puppeteer.launch(). Below that import, we create a skeleton for our generatePDF() function, taking in a single argument html as a string.Ĭonst browser = await puppeteer.launch() This is what we'll use to generate our PDF. Here, we begin by importing the puppeteer dependency we installed earlier. lib/generatePDF.js import puppeteer from "puppeteer" This function will take in some HTML and CSS for the contents of our PDF and then output it as an actual PDF: Our first task is to write the function that we'll use to actually generate our PDF. Next, install the dependencies for the boilerplate:Īfter that, we need to install the puppeteer package from NPM which will help us generate our PDF:įinally, start the development server up:Īfter this, we have everything we need to do our work. First, let's clone a copy of that to our computer: For this tutorial, we're going to use the CheatCode Node.js Boilerplate to give us a starting point for our work. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |