我們目前不接受 DOCX 文件作為輸入。但是我們可以生成 DOCX 文件作為輸出。我們期待在不久的將來全面支持 DOCX。
C++ 庫是一個獨立的解決方案,不需要安裝任何第三方軟件。
在不損失質量的情況下使 DOCX 文件更小。 C++ 庫為開發人員提供了一個集成的 API 來優化 DOCX 內容。 DOCX 優化通過壓縮 DOCX 文件中的圖像以及刪除未使用的數據來實現。
使用 'Aspose.Words for C++' 輕鬆實現電子書無損壓縮和內容優化。以下示例演示瞭如何在 C++ 中優化 DOCX 文件的內容:
dotnet add package Aspose.Words.Cpp
複製
using namespace Aspose::Words;
auto doc = MakeObject<Document>(u"Input.docx");
doc->Cleanup();
auto nodes = doc->GetChildNodes(NodeType::Shape, true);
for (const auto& shape : System::IterateOver<Shape>(nodes))
{
if (shape->get_HasImage())
{
// 由開發者選擇用於圖像壓縮的庫。
auto image = System::Drawing::Image::Fromstream(shape->get_ImageData()->ToStream());
// ...
// 壓縮圖像並將其設置回形狀。
shape->get_ImageData()->SetImage("yourCompressedImage");
}
}
doc->Save(u"Output.epub");
using namespace Aspose::Words;
auto doc = MakeObject<Document>(u"Input.docx");
doc->Cleanup();
auto nodes = doc->GetChildNodes(NodeType::Shape, true);
for (const auto& shape : System::IterateOver<Shape>(nodes))
{
if (shape->get_HasImage())
{
// 由開發人員選擇用於圖像壓縮的庫。
auto image =
System::Drawing::Image::FromStream(shape->get_ImageData()->ToStream());
// ...
// 壓縮圖像並將其設置回形狀。
shape->get_ImageData()->SetImage("yourCompressedImage");
}
}
auto saveOptions = MakeObject<PdfSaveOptions>();
saveOptions->set_CacheBackgroundGraphics(true);
doc->Save(u"Output.epub", saveOptions);
using namespace Aspose::Words;
auto doc = MakeObject<Document>(u"Input.docx");
doc->Cleanup();
auto nodes = doc->GetChildNodes(NodeType::Shape, true);
for (const auto& shape : System::IterateOver<Shape>(nodes))
{
if (shape->get_HasImage())
{
// 由開發者選擇用於圖像壓縮的庫。
auto image = System::Drawing::Image::Fromstream(shape->get_ImageData()->ToStream());
// ...
// 壓縮圖像並將其設置回形狀。
shape->get_ImageData()->SetImage("yourCompressedImage");
}
}
doc->Save(u"Output.epub");
using namespace Aspose::Words;
auto doc = MakeObject<Document>(u"Input.docx");
doc->Cleanup();
auto nodes = doc->GetChildNodes(NodeType::Shape, true);
for (const auto& shape : System::IterateOver<Shape>(nodes))
{
if (shape->get_HasImage())
{
// 由開發人員選擇用於圖像壓縮的庫。
auto image =
System::Drawing::Image::FromStream(shape->get_ImageData()->ToStream());
// ...
// 壓縮圖像並將其設置回形狀。
shape->get_ImageData()->SetImage("yourCompressedImage");
}
}
auto saveOptions = MakeObject<OoxmlSaveOptions>();
saveOptions->set_CompressionLevel(CompressionLevel::Maximum);
doc->Save(u"Output.epub", saveOptions);
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto shape = builder->InsertImage(u"Input.docx");
auto saveOptions = MakeObject<ImageSaveOptions>(SaveFormat::Docx);
shape->GetShapeRenderer()->Save(u"Output.epub", saveOptions);
有三個選項可以將 Aspose.Words for C++ 安裝到您的開發人員環境中。請選擇符合您需求的一種,並按照分步說明進行操作:
您可以使用這個 C++ 庫在 Microsoft Windows 、Linux 和 macOS 操作系統上開發軟件:
如果您為 Linux 或 macOS 開發軟件,請查看產品文檔中 fontconfig 和 mesa-glu 開源包)的信息。