我們目前不接受 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.