Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DynamicWebsite/modules/pdf.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
37 lines (34 sloc)
1.06 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-magic-numbers */ | |
/* eslint-disable max-lines-per-function */ | |
'use strict' | |
const pdf = require('/home/cc/Documents/340CT_Project/node_modules/pdf/lib/pdf').pdf | |
const fs = require('fs') | |
module.exports = class Order { | |
createPDF(data) { | |
console.log('data = ', data) | |
const doc = new pdf() | |
doc.text(20, 20, 'Menu') | |
doc.text(20, 30, 'Name') | |
doc.text(100, 30, 'Type') | |
doc.text(140, 30, 'Price') | |
let line = 40 | |
for(let i = 0; i< data.itemName.length; i++) { | |
doc.text(20, line, data.itemName[i]) | |
doc.text(100, line, data.itemType[i]) | |
doc.text(140, line,`£ ${data.itemPrice[i]}`) | |
line = line + 10 | |
} | |
doc.setProperties({ | |
title: 'Menu', | |
subject: 'Items in the current Menu', | |
author: 'User', | |
keywords: 'Menu, Restaurant, Price,', | |
creator: 'User'}) | |
doc.addPage() | |
const fileName = `testFile${new Date().getSeconds()}.pdf` | |
// eslint-disable-next-line handle-callback-err | |
fs.writeFile(fileName, doc.output(), (err, data) => { | |
console.log(`${fileName} was created! great success!`) | |
}) | |
} | |
} |