-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathindex.js
More file actions
19 lines (17 loc) · 724 Bytes
/
index.js
File metadata and controls
19 lines (17 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const fs = require('fs')
const http = require('http')
const pdf = require('../../')
const tmpl = fs.readFileSync(require.resolve('../businesscard/businesscard.html'), 'utf8')
const server = http.createServer(function (req, res) {
if (req.url === '/favicon.ico') return res.end('404')
const html = tmpl.replace('{{image}}', `file://${require.resolve('../businesscard/image.png')}`)
pdf.create(html, { width: '50mm', height: '90mm' }).toStream((err, stream) => {
if (err) return res.end(err.stack)
res.setHeader('Content-type', 'application/pdf')
stream.pipe(res)
})
})
server.listen(8080, function (err) {
if (err) throw err
console.log('Listening on http://localhost:%s', server.address().port)
})