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!
timschoch
I'm trying to create a PDF from a Notion HTML Export. So far I've used the tipps from this post to get Prince running, but when adding
Prince().option("no-default-style")
the inline css code of the header is rendered into the document.
Without the no-default-style option the PDF is rendered correctly, but obviously with the default styles.
I know this is a very specific question, but maybe someone has experienced this too?

EDIT: It's not only the style-tag, everything in the header gets added at the beginning of the body
mikeday
Why exactly do you wish to use the --no-default-style option? It will require specifying your own CSS for all the basic HTML elements.
timschoch
Because prince would include its css after the custom css making it incredibly anoying to override settings of prince. I want my own styles to take precedence over Prince's CSS