Forum Samples, Tips and Tricks

How to send the css-file param on the Nodejs Prince call?

shivaram
How to send the style/css param on the Nodejs Prince call?

https://www.npmjs.com/package/prince
const Prince = require("prince")
const util   = require("util")
 
Prince()
    .styles("test.css") //  < this is not working
    .inputs("test.html")
    .output("test.pdf")
    .execute()
    .then(function () {
        console.log("OK: done")
    }, function (error) {
        console.log("ERROR: ", util.inspect(error))
    })

Note: On the above Prince() code, the styles() function doesn't exist? So, not sure how to pass the CSS style as a parameter? Kindly help?

mikeday
I think it is Prince().option("style", "test.css").
shivaram
Thank you Mike, it works!
shivaram
Just one thing: How to pass multiple style files?
mikeday
It doesn't look like the Node interface has support for that, so you would either need to extend the API or pass one style file that @imports the others.
mikeday
(The Prince command-line program does allow the --style option to be repeated multiple times, but the Node API appears to overwrite the option value if you set it multiple times).
shivaram
ok Mike, I will go with single css importing others, thx
vrwt
How to use '--no-default-style' options?

const Prince = require("prince")
const util   = require("util")
 
Prince()
.option("style", "no-default-style")
/*.option("style", "no-default-style", true)*/
.inputs("mydoc.html")
.output("mydoc.pdf")
.execute()
.then(function () {
    console.log("OK: done")
}, function (error) {
    console.log("ERROR: ", util.inspect(error))
})


Thanks. :)
mikeday
I think you would just use Prince().option("no-default-style"), right?
vrwt
Thank you Mike, it works!