You can see we're rendering out our SVG file to a PDF. Then, we also need to document end our stream. We can take our document and pipe that into response. Now, since we have a document and we have a background SVG, we can bring in the SVG-to-PDFKit package, which I've already installed, so SVG-to-PDF and require SVG-to-PDFKit, and essentially, we're just going to say SVG-to-PDF and write the document that background. We want us to have a layout of landscape and a size of A4, essentially the default document size for printer. We'll call this our PDFDocument and require PDFKit which I've npm installed already. Then, npm install pdfkit which we can bring in. Since we're going to convert this into a PDF, I'm going to do it this way where I grab the background, and we'll say this is File System readFileSync and read the background in SVG, and we'll essentially stringify it or two string. If I hit save there and refresh, you'll see the entire SVG file. With the File System, you essentially createReadStreams, so I could read that file in, background SVG and pipe it into response. FS the File System, require FS, and have a file in here called background.SVG which I can bring in. We'll get the route, the request response, and we'll send back "hello," and listen on port:3000, save, and we'll open our localhost:3000 here and see "hello." I've already installed express, so let's just set that up by requiring express, creating our app from express, setting up the root route. Instructor: I'm going to start nodemon on this index file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |