使大的 DOC 文件更小而不损失质量。删除不必要和未使用的数据。在代码中缩小 DOC 文件的大小。 JavaScript 库为开发人员提供了一个集成的 API 来优化 DOC 内容。
JavaScript 库是一个独立的解决方案,不需要安装任何第三方软件。
使用 'Aspose.Words for Node.js via .NET' 可以轻松实现无损压缩和深度内容优化。以下示例演示了如何优化 JavaScript 中的 JavaScript DOC 文件的内容:
npm install @aspose/words
复制
const aw = require('@aspose/words');
var doc = new aw.Document("Input.doc");
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.doc")
const aw = require('@aspose/words');
var doc = new aw.Document("Input.doc");
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.doc", saveOptions)
const aw = require('@aspose/words');
var doc = new aw.Document("Input.doc");
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.doc")
const aw = require('@aspose/words');
var doc = new aw.Document("Input.doc");
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.doc", saveOptions)
const aw = require('@aspose/words');
var doc = new aw.Document()
var builder = new aw.DocumentBuilder(doc)
shape = builder.insertImage("Input.doc")
var saveOptions = new aw.Saving.ImageSaveOptions(aw.SaveFormat.Doc)
shape.getShapeRenderer().save("Output.doc", 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.