Git Product home page Git Product logo

novlr / docx.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zerdah/docx.js

0.0 2.0 0.0 132 KB

DOCX.js is a JavaScript library for converting the data in base64 DOCX files into HTML - and back! Please note that this library is licensed under the Microsoft Office Extensible File License - a license NOT approved by the OSI. While this license is based off of the MS-PL, which is OSI-approved, there are significant differences.

Home Page: http://blog.innovatejs.com/?cat=17

License: Other

docx.js's Introduction

DOCX.js

DOCX.js is a JavaScript library for converting the data in binary DOCX files into HTML - and back! Please note that this library is licensed under the Microsoft Office Extensible File License - a license NOT approved by the OSI. While this license is based off of the MS-PL, which is OSI-approved, there are significant differences.

DOCX.js depends on JSZip

This fork is modified to accept binary ArrayBuffer .docx's, and output blob .docx's. It includes support for headers, paragraphs, bold, italics, strikethrough, ordered lists, links (with titles too), inline code, code blocks, block quotes, and limited support for tables. Works well in combination with markdown, supporting much of what markdown supports.

This fork is not well tested across platforms. It will not be receiving further updates. I'll look at pull requests, but you should consider forking instead.

###Create a .docx from a DOM element docx.export(domEl, options)

See an example in action. Click Download .docx at the top to download the page.

Example:

var docDOM = document.getElementById('example');
var docObject = docx.export(docDOM, // required DOM Object
{
	creator: "Creator", // optional String
	lastModifiedBy: "Last person to modify", // optional String
	created: new Date(), // optional Date Object
	modified: new Date() // optional Date Object
});
var link = document.createElement('a');
link.appendChild(document.createTextNode("Download Link Text"));
link.title = "Download Title";
link.download = "FilenameHere.docx";
link.href = docObject.href();
document.getElementById("example").appendChild(link);

Memory Leak Warning! .href() creates a blobURL that must be later revoked with docObject.revoke() or it will stay in memory until the page changes/closes. Browsers that do not support blobURL's should access the blob directly with docObject.blob

###Create a DOM Element from a .docx docx.read(arrayBuffer)

Example:

document.getElementById('files').addEventListener('change', function(e){
var reader = new FileReader();
	reader.onload = function(ev) {
		var docObject = docx.read(ev.target.result); // accepts ArrayBuffers
		document.getElementById("center").appendChild(docObject.DOM);
	};
	reader.readAsArrayBuffer(e.target.files[0]);
}, false);

docx.js's People

Contributors

zerdah avatar pinzhang avatar muhleder avatar

Watchers

James Cloos avatar  avatar

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.