Skip to content

Commit

Permalink
Support relative links using base option
Browse files Browse the repository at this point in the history
  • Loading branch information
chipta authored and marcbachmann committed Feb 16, 2016
1 parent 02748ee commit b791d6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var fs = require('fs')
var pdf = require('../')
var path = require('path')

var args = process.argv.slice(2)

Expand All @@ -22,7 +23,10 @@ function help () {

function htmlpdf (source, destination) {
var html = fs.readFileSync(source, 'utf8')
pdf.create(html).toFile(destination, function (err, res) {
var options = {
base: 'file://' + path.resolve(source)
}
pdf.create(html, options).toFile(destination, function (err, res) {
if (err) throw err
})
}
6 changes: 5 additions & 1 deletion src/scripts/pdf_a4_portrait.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ page = webpage.create()
if options.httpHeaders
page.customHeaders = options.httpHeaders

page.content = json.html
if options.base
page.setContent(json.html, options.base)
else
page.setContent(json.html, null)

page.viewportSize = vp if vp = options.viewportSize
totalPages = 0

Expand Down

0 comments on commit b791d6d

Please sign in to comment.