npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

quill-to-word

v1.3.0

Published

Transforms a QuillJS delta into a Word Document

Downloads

4,662

Readme

npm Travis (.com) GitHub last commit npm GitHub issues NPM

QuillToWord

Simple Description: Turn the content in your QuillJS editor into a downloadable Microsoft Word document.

Technical Description: Convert a QuillJS delta object into a .docx file.

Check out a live Angular demo on Stackblitz.

How to Install

Install using npm:

npm i quill-to-word --save

How Do I Use It?

Pass a QuillJS delta object to the generateWord() function of the quill-to-word package. Be sure to await the generateWord() function, because it returns a Promise.

const quillDelta = quillInstance.getContents();
const doc = await quillToWord.generateWord(quillDelta);

quillInstance refers to the object created by calling new Quill().

What Does the Package Do?

This package creates a Microsoft Word DOCX file from a QuillJS Delta. In short, this package will allow you to download the contents of your QuillJS in-browser editor as a Word document.

How Does It Work?

QuillJS stores its content in a delta format. QuillToWord parses a Quill delta object into a paragraph format using QuillJSParser. Then, QuillToWord generates a Word document, using the popular DOCX package.

How Can I Download the Word Document from the Browser?

You can download the Word document created by QuillToWord by using the FileSaver package. You'll need to install file-saver.

npm i file-saver --save

npm i @types/file-saver --save-dev

Here is an example of downloading from a browser.

import { saveAs } from 'file-saver';
import * as quillToWord from 'quill-to-word';
import * as quill from 'quilljs';

const quillInstance = new Quill();
const delta = quillInstance.getContents();
const quillToWordConfig = {
    exportAs: 'blob'
};
const docAsBlob = await quillToWord.generateWord(delta, quillToWordConfig);
saveAs(docAsBlob, 'word-export.docx');

How Can I Configure QuillToWord?

QuillToWord supports two configurable options: export configuration and style configuration.

Export Configuration

By default, QuillToWord will return a docx object from a call to generateWord(). QuillToWord is also capable of returning a Blob, a Buffer, or a base64 string. To obtain one of these alternative objects, pass a configuration object as the second argument to generateWord(). See the example below.

const quill_delta = quillInstance.getContents();
const configuration = {
    exportAs: 'blob' // could also be 'buffer', 'base64', or 'doc'
}

const docx_blob = await quillToWord.generateWord(quill_delta, configuration); // returns Promise<Blob>

Style Configuration

As you are likely aware, Microsoft Word documents enable users to specify style formats for various types of text within a document. For instance, specific fonts, sizes, and spacing can be set for headings, normal text, block quotes, and so forth.

QuillToWord is prepackaged with default styles for several types of text commonly used within a quill editor: normal, heading 1, heading 2, lists, code blocks, and block quotes. If you prefer to specify your own styling for these types of text, you can pass a configuration object as the second argument to generateWord(). The configuration object should satisfy the following interface:

interface Configuration {
    paragraphStyles: {
        normal?: {  // this is the name of the text type that you'd like to style
            paragraph?: {
                spacing?: {
                    line?: number;
                    before?: number;
                    after?: number;
                },
                alignment?: AlignmentType // from docx package
                indent?: {
                    left?: number;
                    hanging?: number;
                    right?: number;
                }
            },
            run?: {
                font?: string;
                size?: number;
                bold?: boolean;
                color?: string; // as hex value e.g., ffaaff
                underline?: {
                    type?: UnderlineType; // from docx package
                    color?: string // just use 'auto'
                }
                italics?: boolean;
                highlight?: string; // must be named values accepted by Word, like 'yellow'
            }
        }
    }
}

Note that all of the same properties shown for normal here can be set for the following: heading_1, heading_2, list_paragraph, code_block, and block_quote.

Also, be aware that most of the formats are based on the normal format. As a result, modifying the normal format could cause changes in the other formats as well.

Now, let's see an example of configuring the header format. The configuration object in the example below will override the default styling for heading level one.

const quill_delta = quillInstance.getContents();
const config: Config = {
    paragraphStyles: {
        header_1: {
            paragraph: {
                spacing: {
                    before: 1200,
                    after: 1000
                }
            },
            run: {
                size: 64,
                bold: true,
                color: 'ff88bb'
            }
        }
    }
};
const doc = await quillToWord.generateWord(quill_delta, config);