Giter Club home page Giter Club logo

Comments (6)

VolodymyrBaydalka avatar VolodymyrBaydalka commented on May 24, 2024 3

As far as I know csp restricts from appending <style> into document, but not from creating <style> element. Knowing that, there is one quick workarround but only for chrome (for know), but maybe it will give you some ideas for futher investigation:

var container = document.getElementById("doc");
// create dummy container for styles
var stylesContainer = document.createElement("div");

docx.renderAsync(file, container, stylesContainer).then(function(x){ 
    // convert rendered styles into CSSStyleSheet
    var styles = Array.from(stylesContainer.children).map(s => {
        var css = new CSSStyleSheet();
        css.replaceSync(s.innerHTML);
        return css;
    }); 

    // apply styles to document
    document.adoptedStyleSheets = styles;
    // or apply styles to each element of content container manually
});

from docxjs.

theimo1221 avatar theimo1221 commented on May 24, 2024

I'm working on this.

from docxjs.

VolodymyrBaydalka avatar VolodymyrBaydalka commented on May 24, 2024

Hi,
Potentially it's possible to apply all styles via element styles, but there come issues

  • custom fonts will not be supported
  • numbering may not work correctly

from docxjs.

isocroft avatar isocroft commented on May 24, 2024

@theimo1221 I think a good compromise might be to load the docxjs script and other helper scripts like jszip inside an iframe and then use the CSP (<iframe csp="" ) attribute.

Have you tried this ?

from docxjs.

theimo1221 avatar theimo1221 commented on May 24, 2024

I did and it didn't work in our application.
But I found a proper work around and added it as a setting.
You can check my fork, from which I'll open more PR's once the current ones are merged.

from docxjs.

theimo1221 avatar theimo1221 commented on May 24, 2024

#17 resolves the topic for me.

from docxjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.