hajareshyam / pdf-creator-node

This package is used to generate HTML to PDF in Nodejs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not link external css file

db-conception opened this issue · comments

Hello,

I am trying to link an external css file. But it doesn't works

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>DECLARATION DE NON-CONDAMNATION et de FILIATION</title>
    <link href="style.css" rel="stylesheet">
  </head>

Any help out there?

Any help out there?

As temporary solution, I use fs to read the css file, and inject it inside the template using {{ this.styles }}

Any help out there?

var fs = require("fs");
var path = require("path");



// get css from style file
const cssRules = fs.readFileSync(
path.join(process.cwd(), "./template/commun/style.css"),
"utf8"
);
// merge computed datas to data object
data.styles = cssRules;

Any help out there?

I can link the css file, but I only test this with the localhost.

<link href="http://localhost:3000/css/style.css" rel="stylesheet"/>

@db-conception U can attachment the HTML file?

In my case, the CSS wasn't loading because it could not load the images.
I mean, there was a error with my images when the PDF was created.
I hope this be useful.