我们目前不接受 DOCX 文件作为输入。但是我们可以生成 DOCX 文件作为输出。我们期待在不久的将来全面支持 DOCX。
JavaScript 库是一个独立的解决方案,不需要安装任何第三方软件。
在不损失质量的情况下使 DOCX 文件更小。 JavaScript 库为开发人员提供了一个集成的 API 来优化 DOCX 内容。 DOCX 优化是通过压缩 DOCX 文件中的图像以及删除未使用的数据来实现的。
使用 'Aspose.Words for Node.js via .NET' 轻松实现电子书无损压缩和内容优化。以下示例演示了如何在 JavaScript 中优化 DOCX 文件的内容:
npm install @aspose/words
复制
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()) {
// 由开发人员选择图像压缩的库。
const imageData = shape.getImageData().toStream();
// ...
// 压缩图像并将其设置回形状。
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()) {
// 由开发人员选择图像压缩的库。
const imageData = shape.getImageData().toStream();
// ...
// 压缩图像并将其设置回形状。
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()) {
// 由开发人员选择图像压缩的库。
const imageData = shape.getImageData().toStream();
// ...
// 压缩图像并将其设置回形状。
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()) {
// 由开发人员选择图像压缩的库。
const imageData = shape.getImageData().toStream();
// ...
// 压缩图像并将其设置回形状。
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)
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.