hajareshyam / pdf-creator-node

This package is used to generate HTML to PDF in Nodejs
MIT License
238 stars 79 forks source link

Can not link external css file #87

Open db-conception opened 2 years ago

db-conception commented 2 years ago

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>
0xMelkor commented 2 years ago

Any help out there?

db-conception commented 2 years ago

Any help out there?

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

db-conception commented 2 years ago

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;

Caresle commented 1 year ago

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"/>
Isrolik-MorYosef commented 1 year ago

@db-conception U can attachment the HTML file?

Migue98 commented 1 year ago

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.