現在、DOCX ファイルを入力として受け付けていません。ただし、出力として DOCX ファイルを生成することはできます。近い将来、DOCX が完全にサポートされることを楽しみにしています。
JavaScript ライブラリはスタンドアロンソリューションであり、サードパーティのソフトウェアをインストールする必要はありません。
品質を損なうことなく DOCX ファイルを小さくします。 JavaScript ライブラリは、DOCX コンテンツを最適化するための統合APIを開発者に提供します。 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.