How to export html page to ms. word (.doc) with external CSS?

Herlina Astari picture Herlina Astari · Aug 31, 2015 · Viewed 9.9k times · Source

I want to export html page to .doc format with external CSS. I'm using jQuery.wordexport.js and FileSaver.js.

This is what I want to export:

<div id="export">Content</div>

And this is the js:

<script type="text/javascript">
    jQuery(document).ready(function($) {
        $("a.word-export").click(function(event) {
            $("#export").wordExport();
        });
    });
    </script>

I also include the external css:

<link href="css/style.css" rel="stylesheet">

I can export html page to word, but the problem is it doesn't let me to include the external CSS. It works with inline CSS but it makes the code looks messy and I have to type the same style to every page. And also, it doesn't read margin and padding, so I cannot manage the position of the text.

Can anyone help me? I really appreciate it. Thank you!

Answer

Vuthy Sok picture Vuthy Sok · Aug 31, 2015

You can put full path (Absolute Paths) of css file <link href="{Absolute Paths}css/style.css" rel="stylesheet"> beause Ms-Word can't read Relative Path.

Example:

<link href="http://www.domain.com/css/style.css" rel="stylesheet">