2.1.0 • Published 10 months ago

@mtfm/docx-to-html v2.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

@mtfm/docx-to-html

Provides a converter which converts .docx files (documents created by Microsoft Word) to HTML.

This package is part of the Mutaforma monorepo.

Table of contents

Installation

npm install @mtfm/docx-to-html

Usage

Minimum example

The conversion result is not persisted to disk, requiring programmatic handling to store or further process the output.

import { DocxToHtmlConverter } from "@mtfm/docx-to-html";

const converter = new DocxToHtmlConverter({
    input: "path/to/the/docx/file.docx",
});

const execOpResult = converter.execute();

if (execOpResult.isErr()) {
    const error = execOpResult.error;
    // Handle error during execution
    return;
}

const finalResult = execOpResult.value;

// Handle the conversion result

Persisting result to disk

To persist the conversion result to disk, simply provide the desired output folder path via the output property of the options object passed to the converter.

If the specified folder structure does not yet exist, it will be automatically created. Furthermore, the conversion result can still be processed programmatically.

import { DocxToHtmlConverter } from "@mtfm/docx-to-html";

const converter = new DocxToHtmlConverter({
    input: "path/to/the/docx/file.docx",
    output: "path/to/output/folder",
});

// Same as in minimum example

Customizing conversion configuration

To customize the default conversion configuration, you can specify the path to a custom configuration file in JSON format using the config property of the options object passed to the converter.

For a comprehensive overview of all available configuration settings and the required structure of the configuration file, please refer to the official Mutaforma documentation.

import { DocxToHtmlConverter } from "@mtfm/docx-to-html";

const converter = new DocxToHtmlConverter({
    input: "path/to/the/docx/file.docx",
    output: "path/to/output/folder",
    config: "path/to/custom/config/file.json",
});

// Same as in minimum example

API

DocxToHtmlConverter

Methods

NameParametersReturns
constructorIDocumentConverterOpts<...>DocxToHtmlConverter
executePromise<Result<IDocumentConverterResult, Error>>

IDocumentConverterOpts<string | Buffer>

Properties

NameTypeMandatoryDescription
inputstring or BufferyesEither a path to a *.docx file on disk or an already buffered *.docx file
outputstringnoA path to a folder to which the output should be saved
configstringnoPath to a custom configuration file in JSON format

IDocumentConverterResult

Properties

NameTypeMandatoryDescription
imagesIAsset[]yesAll images contained within the *.docx file
documentIAssetyesThe HTML document

IAsset

Properties

NameTypeMandatoryDescription
idstringyesThe asset id
datastringyesThe asset data
dataEncodingstringyesThe asset data encoding
namestringyesThe name of the asset
extstringyesThe file extension of the asset

License

MIT

2.1.0

10 months ago

2.0.0

10 months ago

1.2.0

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.0

10 months ago