dom2docx.js

An example page to show how to use the dom2docx script.
The div below (#input) is passed to Dom2Docx and a Docx file is generated and downloaded
View on Github

Paragraphs

Example paragraph with some bold text, some italic text, some underlined text, and some strikethrough text. You can also highlight text and change the baseline and set the text to superscript or subscript. Oh, yeah, and you can set the text size to small.

Lists

Unordered List

Description List

Description Term 1
Description Description 1
Description Term 2
Description Description 2
Script File:
      create = document.getElementById("create");

      create.addEventListener("click", function() {
        // #input element in dom contains data which is to be converted to .docx
        input = document.getElementById("input");

        // Create instance on Dom2Docx
        dom2docx = new Dom2Docx(input);

        // Creates the dom to a File Blob object
        docx = dom2docx.create();

        // you can use `URL.createObjectURL` to create
        link = document.createElement("a");
        link.href = (window.URL || window.webkitURL).createObjectURL(docx);
        link.download = "example.docx";
        link.textContent = "Download File";
        document.getElementById("js-create").appendChild(link);

        // Using FileSaver
        saveAs(docx, "example.docx");
      });