The code to compress EPUB in JavaScript

High-performance Node.js library to optimize the size and content of EPUB files while maintaining their original quality

Develop EPUB processing software in Node.js using EPUB Optimization API. This powerful Node.js solution helps you optimize and reduce the size of EPUB files effortlessly. Test EPUB compressing capabilities online for free!

View code snippet

Compress DOCX in JavaScript

We currently do not accept DOCX files as input. But we can produce DOCX files as an ouput. We look forward to full DOCX support in the near future.

JavaScript library is a stand-alone solution and doesn't require any third party software installed.

Reduce the size of DOCX files using JavaScript

Make DOCX files smaller without loss of quality. The JavaScript library provides developers with an integrated API to optimize DOCX content. DOCX optimization occurs by compressing images inside DOCX files, as well as by removing unused data.

Ebook lossless compression and content optimization made easy with 'Aspose.Words for Node.js via .NET'. The following example demonstrates how to optimize the content of a DOCX file in JavaScript:

Code example in JavaScript to compress EPUB files
Upload a file you want to optimize/compress
Run code
Select the target format from the list
npm install @aspose/words
Copy
const aw = require('@aspose/words');

var doc = new aw.Document("Input.docx");
doc.cleanup();

var shapes = doc.getChildNodes(aw.NodeType.Shape, true)
for (var shape of shapes) {
    if (shape.hasImage()) {
        // It's up to developer to choose the library for image compression.
        const imageData = shape.getImageData().toStream();

        // ...
        // Compress image and set it back to the shape.
        shape.getImageData().setImage(compressedImageBuffer);
    }
}

doc.save("Output.epub")
const aw = require('@aspose/words'); var doc = new aw.Document("Input.docx"); doc.cleanup(); var shapes = doc.getChildNodes(aw.NodeType.Shape, true) for (var shape of shapes) { if (shape.hasImage()) { // It's up to developer to choose the library for image compression. const imageData = shape.getImageData().toStream(); // ... // Compress image and set it back to the shape. shape.getImageData().setImage(compressedImageBuffer); } } var saveOptions = new aw.Saving.PdfSaveOptions() saveOptions.cacheBackgroundGraphics = true doc.save("Output.epub", saveOptions) const aw = require('@aspose/words'); var doc = new aw.Document("Input.docx"); doc.cleanup(); var shapes = doc.getChildNodes(aw.NodeType.Shape, true) for (var shape of shapes) { if (shape.hasImage()) { // It's up to developer to choose the library for image compression. const imageData = shape.getImageData().toStream(); // ... // Compress image and set it back to the shape. shape.getImageData().setImage(compressedImageBuffer); } } doc.save("Output.epub") const aw = require('@aspose/words'); var doc = new aw.Document("Input.docx"); doc.cleanup(); var shapes = doc.getChildNodes(aw.NodeType.Shape, true) for (var shape of shapes) { if (shape.hasImage()) { // It's up to developer to choose the library for image compression. const imageData = shape.getImageData().toStream(); // ... // Compress image and set it back to the shape. shape.getImageData().setImage(compressedImageBuffer); } } var saveOptions = new aw.Saving.OoxmlSaveOptions() saveOptions.compressionLevel = aw.Saving.CompressionLevel.Maximum doc.save("Output.epub", saveOptions) const aw = require('@aspose/words'); var doc = new aw.Document() var builder = new aw.DocumentBuilder(doc) shape = builder.insertImage("Input.docx") var saveOptions = new aw.Saving.ImageSaveOptions(aw.SaveFormat.Docx) shape.getShapeRenderer().save("Output.epub", saveOptions)
Run code

How to compress DOCX in JavaScript

  1. Install Aspose.Words for Node.js via .NET.
  2. Add a library reference (import the library) to your JavaScript project.
  3. Open the source DOCX file in JavaScript.
  4. Compress DOCX without losing quality.
  5. Call the Document.cleanup() method. The resulting code may vary depending on the output file format.
  6. Get the compressed result as a DOCX file.

JavaScript library to optimize and compress EPUB files

We host our Node.js via .Net packages in NPM repositories. Please follow the step-by-step instructions on how to install "Aspose.Words for Node.js via .NET" to your developer environment.

System Requirements

This package is compatible with Node.js 14.17.0 or higher.

Other supported file format optimizations

You can optimize files in many other file formats:

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2025. All Rights Reserved.