node-html-pdf icon indicating copy to clipboard operation
node-html-pdf copied to clipboard

Bold text are ignored from html to pdf

Open 0xDones opened this issue 7 years ago • 34 comments

Hello, it seens I can't get the bold text in html files passed to the pdf. I tried different ways to get my text bold but none of the attempts were successful.

My attempts

  1. HTML element <strong></strong>
  2. HTML element <b></b>
  3. CSS property font-weight: bold;

Maybe there is a problem?

0xDones avatar Sep 17 '18 22:09 0xDones

A workaround is to use something like font-weight: 700; property. I am using it and it works pretty fine.

sameer-kumar-jain avatar Sep 19 '18 07:09 sameer-kumar-jain

It didn't work for me, I've read there are some problems with phathonJS and linux...

0xDones avatar Sep 20 '18 17:09 0xDones

Try to add font-weight: bold !important; to the very last child you want to bold. In my experience, the CSS is not inherited to subsequent child elements.

dorklord23 avatar Sep 24 '18 07:09 dorklord23

It's happening to me in Mojave. However, once deployed to Heroku, works fine.

xpander001 avatar Oct 03 '18 17:10 xpander001

@xpander001 did you find a workaround? Same here, and yes just upgraded OS.

simoncolab avatar Nov 03 '18 06:11 simoncolab

+1

xrado avatar Nov 25 '18 14:11 xrado

Same here, worked on Sierra, doesn't work on Mojave.

tconn89 avatar Jan 14 '19 18:01 tconn89

any update here? bold text are still not working...

selo796 avatar Jan 19 '19 13:01 selo796

Can someone please have a look at this?

CarrieZ0320 avatar Jan 28 '19 22:01 CarrieZ0320

I have the same issue where locally (Mac) the bold text doesn't show up, but once deployed on Heroku it works as expected. Unless you plan to serve this from your mac, I wouldn't worry about it. Also, it's not this package that has the issue, it's a dependency.

MarcGodard avatar Mar 06 '19 15:03 MarcGodard

My guess is that you might be using some unique fonts which don't support BOLD. I've tried using google fonts it didn't work. But if I used 'DejaVuSans' font, it worked for me. My suggestion is to use that font which supports BOLD.

kavishatalsania avatar Apr 29 '19 04:04 kavishatalsania

@kavishatalsania See my answer above. @dpolicastro this can be closed. If you want this to be an issue, add an issue to the broken dependency.

MarcGodard avatar Apr 29 '19 17:04 MarcGodard

@MarcGodard Thanks for reporting, but before deploying an app to heroku you will probably want to test it, and the best way to do this is locally. It looks like an OS fonts/PhanthomJS problem, but this issue is helping people to address the problem so I'll let it here.

0xDones avatar May 07 '19 14:05 0xDones

For anyone still looking:

I was importing fonts from google. I added the "bold" fonts also when selecting fonts and it worked.

Posting here because I didn't find this solution anywhere else.

ghost avatar Sep 03 '19 07:09 ghost

@sulaysumaria on MacOS?

MarcGodard avatar Sep 03 '19 17:09 MarcGodard

I faced this issue on Linux machine... But you can try on MacOS also, if this solves the problem.

ghost avatar Sep 03 '19 17:09 ghost

@sulaysumaria I didn't have any issues on linux, but I did on MacOS

MarcGodard avatar Sep 03 '19 17:09 MarcGodard

@MarcGodard Is your issue solved? I would be happy to help if you are still facing issue in this.

ghost avatar Sep 04 '19 10:09 ghost

@sulaysumaria No it isn't, but as I said above, it doesn't effect production (on linux), only dev on my mac. So I don't care.

MarcGodard avatar Sep 04 '19 14:09 MarcGodard

@MarcGodard

I'm still facing this issue.

Don't know what to do

un-versed avatar Oct 02 '19 15:10 un-versed

Can you share your environment details..

ghost avatar Oct 02 '19 15:10 ghost

Can you share your environment details..

I'm using a macOS 10.14.5

un-versed avatar Oct 02 '19 15:10 un-versed

In my case, It's working when we are defining in CSS

Now, use b tags to make fonts bold.

ktnthkkr avatar Dec 23 '19 19:12 ktnthkkr

I also encounter this issue (no bold text) when I run my app locally on Mac OS Mojave.

imgaf avatar Jan 07 '20 16:01 imgaf

I have the same issue with macOS Mojave v10.14.6, any updates about fix?

kairiruutel avatar Jan 15 '20 20:01 kairiruutel

i have the same issue with linux, any news ?

MateusRb avatar Jan 31 '20 17:01 MateusRb

Same problem. 😞

asifmohtesham avatar Mar 20 '20 08:03 asifmohtesham

Same here on Linux Mint.

ThomasSonck avatar May 13 '20 14:05 ThomasSonck

I have the same issue with macOS Mojave v10.14.6, any updates about fix?

Maybe this helps others as well, I ended up using Puppeteer for pdf creation:

const browser = await puppeteer.launch();
const page = await browser.newPage();

await page.setContent(templateHtml);

const pdf = await page.pdf({
	format: 'A4',
	printBackground: true
});

await browser.close();

const buffer = Buffer.from(pdf);
const bufferStream = new stream.PassThrough();

bufferStream.end(buffer);

return bufferStream;

kairiruutel avatar May 14 '20 06:05 kairiruutel

A solution that works for my needs : include in the HTML the google font link :

<link` href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600&display=swap" rel="stylesheet">

html {
  font-size: 12px;
  font-family: 'Open Sans' !important;
  font-weight: 400;
}

p.bold {
   font-weight: 600;
}

not perfect but it does the job for me

paulcayon avatar Jul 20 '20 11:07 paulcayon