Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relative link #99

Closed
wants to merge 3 commits into from
Closed

Support relative link #99

wants to merge 3 commits into from

Conversation

chipta
Copy link

@chipta chipta commented Jan 12, 2016

Support relative link for html-pdf command.

This should fix #44 and #13.

@@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I didn't know of that option.

@chipta
Copy link
Author

chipta commented Feb 12, 2016

@marcbachmann any updates?

@marcbachmann
Copy link
Owner

I've squashed that and merged into master. Thanks.

@marcbachmann
Copy link
Owner

I've just published that in [email protected]

@konstantinkrassmann
Copy link

Is there a example for this setting ?

@karex
Copy link

karex commented Feb 17, 2021

I've came across this "relative link"-issue, and found a working solution to create the base URL in the convert script, and it looks like this:

let path = require('path');
let currentPath = 'file:///' + path.resolve('.').replace(/\\/g, '/') + '/';

Then you can pass this base path to the pdf.create method in the options parameter like this:

let options = {
    format: 'A4',
    base: currentPath
};
pdf.create(html, options).toFile(pdfFile, function(err, res) {
    if (err) {
        return console.log(err);
    }
    console.log(res);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

image is not displayed after generating the pdf ?
4 participants