Skip to content

Commit b791d6d

Browse files
chiptamarcbachmann
authored andcommitted
Support relative links using base option
1 parent 02748ee commit b791d6d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

bin/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var fs = require('fs')
44
var pdf = require('../')
5+
var path = require('path')
56

67
var args = process.argv.slice(2)
78

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

2324
function htmlpdf (source, destination) {
2425
var html = fs.readFileSync(source, 'utf8')
25-
pdf.create(html).toFile(destination, function (err, res) {
26+
var options = {
27+
base: 'file://' + path.resolve(source)
28+
}
29+
pdf.create(html, options).toFile(destination, function (err, res) {
2630
if (err) throw err
2731
})
2832
}

src/scripts/pdf_a4_portrait.coffee

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ page = webpage.create()
3232
if options.httpHeaders
3333
page.customHeaders = options.httpHeaders
3434

35-
page.content = json.html
35+
if options.base
36+
page.setContent(json.html, options.base)
37+
else
38+
page.setContent(json.html, null)
39+
3640
page.viewportSize = vp if vp = options.viewportSize
3741
totalPages = 0
3842

0 commit comments

Comments
 (0)