dom-to-image icon indicating copy to clipboard operation
dom-to-image copied to clipboard

Google Fonts not save in image

Open ezramod opened this issue 6 years ago • 6 comments

Hy, i use his script for save div to image, but font family is not apply to jpg/png, have solution to fix this?

my script work here: http://cani.magazin-jucariionline.ro/

ezramod avatar Feb 13 '19 20:02 ezramod

Same here, I get

Error while reading CSS rules from https://fonts.googleapis.com/css?family=Open+Sans:300,400,700&subset=cyrillic,cyrillic-ext,greek,greek-ext,latin-ext,vietnamese SecurityError: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules

I have a React web app and I'm loading Google's font like this:


import React, { Component } from 'react';

// ...

class C extends Component {

    // ...

    componentDidMount() {
        const fontLink = document.createElement('link');

        fontLink.href = 'https://fonts.googleapis.com/css?family=Open+Sans:300,400,700&subset=cyrillic,cyrillic-ext,greek,greek-ext,latin-ext,vietnamese';

        fontLink.rel = 'stylesheet';
        fontLink.type = 'text/css';

        document.body.appendChild(fontLink);

    }

    // ...

}

// ...

~~Other than that, awesome work!~~

~~Scratch that, I just realized that this doesn't generate a real SVG. If saved to a file and opened in a browser, it shows ok but, if opened in InkScape or GIMP, it's empty. Actually, GIMP managed to find an actual SVG that was in the middle of the DOM that I converted, but nothing of the other divs.~~

Scratch that, after much digging, I just realized that this does generate a real SVG, but not all SVG renderers are also HTML renderers, such as InkScape. I'd rather have a pure SVG, so I'll keep looking.

GuiRitter avatar Feb 19 '19 13:02 GuiRitter

i add crossorigin="anonymous" to stylesheet and now is saved

ezramod avatar Feb 20 '19 04:02 ezramod

I tried adding crossorigin="anonymous", and while it doesn't generate any console errors, it does not grab my stylesheets.

forthekill avatar Nov 07 '19 17:11 forthekill

@ezramod Do you have any idea if it's possible to add this to an Angular 2+ app, if yes could you please help me with it?

Abdullilah avatar Apr 28 '20 10:04 Abdullilah

well!!! for me it works like this!!!

example

<link rel="preconnect" crossorigin="anonymous" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap" rel="stylesheet" crossorigin="anonymous">

thanks ezramod for crossorigin="anonymous"

joshmg-77 avatar Feb 18 '21 05:02 joshmg-77

well!!! for me it works like this!!!

example

<link rel="preconnect" crossorigin="anonymous" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap" rel="stylesheet" crossorigin="anonymous">

thanks ezramod for crossorigin="anonymous"

That fixed the issue for me too, thanks!

ghost avatar Jul 13 '24 21:07 ghost