JavaScript中壓縮EPUB的代碼

高效能 Node.js 函式庫可最佳化 EPUB 檔案的大小和內容,同時保持其原始質量

使用 EPUB Optimization API在Node.js中開發 EPUB 處理軟體。這個強大的 Node.js 解決方案可協助您輕鬆最佳化並減少 EPUB 檔案的大小。免費線上測試 EPUB 壓縮功能!

查看代碼片段

在 JavaScript 中壓縮 DOCX

我們目前不接受 DOCX 文件作為輸入。但是我們可以生成 DOCX 文件作為輸出。我們期待在不久的將來全面支持 DOCX。

JavaScript 庫是一個獨立的解決方案,不需要安裝任何第三方軟件。

使用 JavaScript 減小 DOCX 文件的大小

在不損失質量的情況下使 DOCX 文件更小。 JavaScript 庫為開發人員提供了一個集成的 API 來優化 DOCX 內容。 DOCX 優化通過壓縮 DOCX 文件中的圖像以及刪除未使用的數據來實現。

使用 'Aspose.Words for Node.js via .NET' 輕鬆實現電子書無損壓縮和內容優化。以下示例演示瞭如何在 JavaScript 中優化 DOCX 文件的內容:

JavaScript中用於壓縮EPUB文件的代碼示例
上傳要優化/壓縮的文件
運行代碼
從列表中選擇目標格式
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)
運行代碼

如何將 DOCX 壓縮為 JavaScript

  1. 安裝Aspose.Words for Node.js via .NET 。
  2. 將庫引用(導入庫)添加到您的JavaScript項目。
  3. 在JavaScript中打開源DOCX文件。
  4. 在不損失質量的情況下壓縮DOCX 。
  5. 調用Document.cleanup()方法。結果代碼可能因輸出文件格式而異。
  6. 將壓縮結果作為DOCX文件獲取。

JavaScript庫用於優化和壓縮EPUB個文件

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.

其他支持的文件格式優化

您可以優化許多其他文件格式的文件:

5%

訂閱 Aspose 產品更新

獲取直接發送到您的郵箱的每月通訊和優惠。

© Aspose Pty Ltd 2001-2025. 版權所有。