The code to compress EPUB in C++

High-performance C++ library to optimize EPUB content and size retaining the original quality and baseline data

This is a professional solution to optimize and compress EPUB in C++. Use C++ to maximize EPUB optimization/compression speed. Try it online for free!

View code snippet

Compress DOCX in C++

We currently do not accept DOCX files as input. But we can produce DOCX files as an ouput. We look forward to full DOCX support in the near future.

C++ library is a stand-alone solution and doesn't require any third party software installed.

Reduce the size of DOCX files using C++

Make DOCX files smaller without loss of quality. The C++ library provides developers with an integrated API to optimize DOCX content. DOCX optimization occurs by compressing images inside DOCX files, as well as by removing unused data.

Ebook lossless compression and content optimization made easy with 'Aspose.Words for C++'. The following example demonstrates how to optimize the content of a DOCX file in C++:

Code example in C++ to compress EPUB files
Upload a file you want to optimize/compress
Run code
Select the target format from the list
dotnet add package Aspose.Words.Cpp
Copy
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())
    {
        // It's up to developer to choose the library for image compression.
        auto image = System::Drawing::Image::Fromstream(shape->get_ImageData()->ToStream());

        // ...
        // Compress image and set it back to the shape.
        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()) { // It's up to developer to choose the library for image compression. auto image = System::Drawing::Image::FromStream(shape->get_ImageData()->ToStream()); // ... // Compress image and set it back to the shape. 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()) { // It's up to developer to choose the library for image compression. auto image = System::Drawing::Image::Fromstream(shape->get_ImageData()->ToStream()); // ... // Compress image and set it back to the shape. 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()) { // It's up to developer to choose the library for image compression. auto image = System::Drawing::Image::FromStream(shape->get_ImageData()->ToStream()); // ... // Compress image and set it back to the shape. 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);
Run code

How to compress DOCX in C++

  1. Install Aspose.Words for C++.
  2. Add a library reference (import the library) to your C++ project.
  3. Open the source DOCX file in C++.
  4. Compress DOCX without losing quality.
  5. Call the Document.Cleanup() method. The resulting code may vary depending on the output file format.
  6. Get the compressed result as a DOCX file.

C++ library to optimize and compress EPUB files

There are three options to install Aspose.Words for C++ to your developer environment. Please choose one that resembles your needs and follow the step-by-step instructions:

System Requirements

You can use this C++ library to develop software on Microsoft Windows, Linux and macOS operating systems:

  • GCC >= 6.3.0 and Clang >= 3.9.1 are required for Linux
  • Xcode >= 12.5.1, Clang and libc++ are required for macOS

If you develop software for Linux or macOS, please check information on additional library dependencies (fontconfig and mesa-glu open-source packages) in Product Documentation.

Other supported file format optimizations

You can optimize files in many other file formats:

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2025. All Rights Reserved.