Develop document processing software in Node.js using Document Optimization API. This powerful Node.js solution helps you optimize and reduce the size of documents and images effortlessly. Test the compressing capabilities online for free!
Make large files smaller without loss of quality. Delete unnecessary and unused data. Shrink the size of Word and HTML files in JavaScript. Our JavaScript library provides developers with an integrated API to optimize documents in various formats.
This JavaScript library is a stand-alone solution and doesn't require any third party software installed.
The maximum effect can be obtained by optimizing high-resolution images, as well as documents containing such images. Our JavaScript library will help you to compress DOCX, DOC, RTF, ODT, EPUB, HTML, JPG, PNG files.
Optimization of documents without loss of quality made easy with 'Aspose.Words for Node.js via .NET'. The following example shows how to shrink the size of a Word document in JavaScript:
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);
}
}
var saveOptions = new aw.Saving.OoxmlSaveOptions()
saveOptions.compressionLevel = aw.Saving.CompressionLevel.Maximum
doc.save("Output.docx", 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);
}
}
var saveOptions = new aw.Saving.PdfSaveOptions()
saveOptions.cacheBackgroundGraphics = true
doc.save("Output.docx", 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.docx")
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.docx", 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.docx", saveOptions)
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.
This package is compatible with Node.js 14.17.0 or higher.