優化和壓縮C++中的文件

用於優化文件內容和大小的高性能C++庫,保留原始質量和基線數據

使用C++獲得最大的文檔處理速度。這是用C++壓縮 Word、PDF、Web 文檔的強大解決方案。免費在線試用!

查看代碼片段

在 C++ 中壓縮 Word 和 HTML 文檔

在不損失質量的情況下使大文件變小。刪除不必要和未使用的數據。在 C++ 中縮小 Word 和 HTML 文件的大小。我們的 C++ 庫為開發人員提供了一個集成的 API 來優化各種格式的文檔。

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

使用 C++ 減小 Word 和 HTML 文件的大小

通過優化高分辨率圖像以及包含此類圖像的文檔,可以獲得最大的效果。我們的 C++ 庫將幫助您壓縮 HTML、DOCX、DOC、RTF、ODT、EPUB、HTML、JPG、PNG 文件。

使用 'Aspose.Words for C++' 可以輕鬆優化文檔而不降低質量。以下示例顯示瞭如何在 C++ 中縮小 Word 文檔的大小:

C++優化文件內容和大小的代碼示例
上傳要優化/壓縮的文件
運行代碼
從列表中選擇目標格式
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.docx", 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"); } } auto saveOptions = MakeObject<PdfSaveOptions>(); saveOptions->set_CacheBackgroundGraphics(true); doc->Save(u"Output.docx", 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.docx"); 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.docx", saveOptions); using namespace Aspose::Words; auto doc = MakeObject<Document>(); auto builder = MakeObject<DocumentBuilder>(doc); auto shape = builder->InsertImage(u"Input.docx"); // 更新頁面設置以裁剪文檔以適合圖片的大小。 auto pageSetup = builder->get_PageSetup(); pageSetup->set_PageWidth(shape->get_Width()); pageSetup->set_PageHeight(shape->get_Height()); pageSetup->set_TopMargin(0); pageSetup->set_LeftMargin(0); pageSetup->set_BottomMargin(0); pageSetup->set_RightMargin(0); auto saveOptions = MakeObject<ImageSaveOptions>(SaveFormat::Docx); doc->Save(u"Output.docx", saveOptions);
運行代碼

C++如何壓縮PDF、 Word 、JPG等文件格式

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

C++庫來優化和壓縮文件

有三個選項可以將 Aspose.Words for C++ 安裝到您的開發人員環境中。請選擇符合您需求的一種,並按照分步說明進行操作:

系統要求

您可以使用這個 C++ 庫在 Microsoft Windows 、Linux 和 macOS 操作系統上開發軟件:

  • Linux 需要 GCC >= 6.3.0 和 Clang >= 3.9.1
  • Xcode >= 12.5.1 ,macOS 需要 Clang 和 libc++

如果您為 Linux 或 macOS 開發軟件,請查看產品文檔中 fontconfig 和 mesa-glu 開源包)的信息。

最流行的文件格式進行優化

5%

訂閱 Aspose 產品更新

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

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