html2canvas icon indicating copy to clipboard operation
html2canvas copied to clipboard

doesn't support font-family property with multiple value

Open rayax86 opened this issue 10 years ago • 8 comments

Using 0.5.0-beta4, thanks so much for this great module!

The problem I am having is, say I have a class .class { font-family: "somefont", "Arial" } where "somefont" doesn't apply, the end result is elements that are .class would be rendered using Arial in the page, but in the canvas the default font is applied instead.

Any idea?

rayax86 avatar Feb 13 '16 07:02 rayax86

I'm having the same issue.

This is Roboto font, in Google chrome canary screen shot 2016-02-18 at 15 18 27

This is rendered image img055

eZ0 avatar Feb 18 '16 14:02 eZ0

I found the reason: parent of canvas has to have explicit font declaration like so: .container { font-family: Roboto, "Helvetica Neue", sans-serif; }

eZ0 avatar Feb 18 '16 14:02 eZ0

The join/split in CanvasRenderer.prototype.font was stripping out additional fonts. I submitted a fix for it

alana314 avatar May 12 '16 18:05 alana314

I am not sure if this is related, but here I think I am seeing the font rendered correctly, but then layered over with an erroneous font?

rsbondi avatar Jun 13 '16 17:06 rsbondi

@eZ0 you are correct! Thank you! As you said, i put font-family: arial at canvas parent element and works!.

Thank you! Thank you!

getJv avatar Sep 28 '16 00:09 getJv

Should be fixed in https://github.com/niklasvh/html2canvas/commit/77d258f1d8eeccf7e38235463a293b512c1ca3d0

niklasvh avatar Dec 12 '17 14:12 niklasvh

not work, I got the same error image

rendered by

html2canvas(this.$refs.iFr, { useCORS: true }).then(canvas => {
        console.log(canvas)

        document.body.appendChild(canvas)

        canvas.toBlob(function(blob) {
          saveAs(blob, 'Dashboard.png')
        })
      })

Custom loaded fonts from server (not CORS) is not render. Used font — based64 css file as font-face to Liberation Serif

ruslankonev avatar Oct 09 '18 14:10 ruslankonev

I have the same problem. You can fix it via clone callback and style it separately.

               onclone: (document) => {
                        document.querySelectorAll('.button span').forEach(element => {
                            element.style['font-family'] = 'sans-serif';
                        });
		}

camohub avatar Jan 21 '22 15:01 camohub