Skip to content

Commit

Permalink
Move the example directory to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbachmann committed Sep 27, 2017
1 parent 543a918 commit f5fe191
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.pdf
!example/businesscard.pdf
!examples/businesscard.pdf
node_modules
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# node-html-pdf
## HTML to PDF converter that uses phantomjs
![image](example/businesscard.png)
[Example Business Card](example/businesscard.pdf)
-> [and its Source file](example/businesscard.html)
![image](examples/businesscard.png)
[Example Business Card](examples/businesscard.pdf)
-> [and its Source file](examples/businesscard.html)

[Example Receipt](http://imgr-static.s3-eu-west-1.amazonaws.com/order.pdf)

Expand Down
Binary file removed example/businesscard.pdf
Binary file not shown.
File renamed without changes.
File renamed without changes
File renamed without changes
19 changes: 19 additions & 0 deletions examples/serve-http/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
})
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ test('pdf.create(html[, options]).toStream(callback)', function (t) {
test('allows custom html and css', function (t) {
t.plan(3)

var template = path.join(__dirname, '../example/businesscard.html')
var template = path.join(__dirname, '../examples/businesscard/businesscard.html')
var filename = template.replace('.html', '.pdf')
var templateHtml = fs.readFileSync(template, 'utf8')

var image = path.join('file://', __dirname, '../example/image.png')
var image = path.join('file://', __dirname, '../examples/businesscard/image.png')
templateHtml = templateHtml.replace('{{image}}', image)

var options = {
Expand Down

0 comments on commit f5fe191

Please sign in to comment.