I am using nodejs with phantom module to generate pdf from html.
First, I read html template and populate it with data and than render it as pdf. I would like bootstrap css to be used to style the page, however styling is inored whatsoever in resulting pdf file.
here is my javascript code:
var phantom = require('phantom');
var htmlTemplate;
fs = require('fs')
fs.readFile('template.html', 'utf8', function (err,data) {
var htmlTemplate = populateTemplate(data, body)
phantom.create(function(ph){
ph.createPage(function(page) {
page.set("paperSize", {
format: "A4",
orientation: 'portrait',
margin: '1cm'
});
page.setContent(htmlTemplate, "", function(){
page.render("../userdata/test.pdf", function(){
console.log("page rendered");
ph.exit();
});
});
})
});
});
and the html template (simplyfied) looks like this:
<!DOCTYPE html>
<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.5/paper/bootstrap.min.css", rel="stylesheet">
<meta charset="utf-8">
</head>
<body>
<div class="container">
<h1>Title</h1>
<%NAME%>
</div>
</body>
</html>
All the markup is rendered to page, but no styling. Even if I use local css file or include style in <style>
element in the head, the results are the same