Cài đặt

Cài đặt Aspose.Slides FOSS cho C++

Aspose.Slides FOSS for C++ is a header-and-source library built with CMake. It has no binary distribution; you integrate it directly into your CMake project from the GitHub repository. No Microsoft Office or other proprietary runtime is required.


Các yêu cầu trước

Yêu cầuChi tiết
Tiêu chuẩn C++C++20 hoặc mới hơn
Hệ thống xây dựngCMake 3.20 hoặc mới hơn
Trình biên dịchGCC 10+, Clang 13+, hoặc MSVC 2019+ (bất kỳ trình biên dịch nào hỗ trợ C++20)
Hệ điều hànhWindows, macOS, Linux
Phụ thuộc bên ngoàiKhông có (tất cả các phụ thuộc đều được tích hợp sẵn hoặc chỉ có header)

1. CMake FetchContent (Recommended)

Cách đơn giản nhất để thêm Aspose.Slides FOSS vào dự án của bạn là sử dụng CMake FetchContent. Thêm đoạn này vào CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)
project(my_slides_app LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
FetchContent_Declare(
    aspose_slides_foss
    GIT_REPOSITORY https://github.com/aspose-slides-foss/Aspose.Slides-FOSS-for-Cpp.git
    GIT_TAG        main
)
FetchContent_MakeAvailable(aspose_slides_foss)

add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE aspose_slides_foss)

CMake tải về kho và tạo target thư viện sẵn sàng. Không cần sao chép thủ công hay cài đặt ở mức hệ thống.

Để cố định một phiên bản cụ thể cho các bản dựng có thể tái tạo, thay thế main bằng một thẻ phát hành hoặc hash commit:

FetchContent_Declare(
    aspose_slides_foss
    GIT_REPOSITORY https://github.com/aspose-slides-foss/Aspose.Slides-FOSS-for-Cpp.git
    GIT_TAG        v26.3.0
)

2. Git Submodule

Nếu bạn muốn đưa mã nguồn vào trong kho của mình (vendoring):

git submodule add https://github.com/aspose-slides-foss/Aspose.Slides-FOSS-for-Cpp.git third_party/aspose_slides_foss

Sau đó tham chiếu nó từ CMakeLists.txt:

add_subdirectory(third_party/aspose_slides_foss)
target_link_libraries(my_app PRIVATE aspose_slides_foss)

3. Build and Verify

Sau khi đã thêm phụ thuộc, cấu hình và biên dịch dự án của bạn:

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build

Tạo một tối thiểu main.cpp để xác minh bản dựng:

#include <Aspose/Slides/Foss/presentation.h>
#include <Aspose/Slides/Foss/export/save_format.h>
#include <Aspose/Slides/Foss/slide.h>
#include <Aspose/Slides/Foss/slide_collection.h>

#include <iostream>

using namespace Aspose::Slides::Foss;

int main() {
    Presentation pres;
    std::cout << "Aspose.Slides FOSS built successfully" << std::endl;
    std::cout << "Slides in empty presentation: " << pres.slides().size() << std::endl;
    return 0;
}

Kết quả mong đợi:

Aspose.Slides FOSS built successfully
Slides in empty presentation: 1

Bắt đầu nhanh: Tạo một Bài thuyết trình với một Hình dạng

Chương trình sau tạo một bản trình bày mới, thêm một hình chữ nhật có văn bản, và lưu nó dưới dạng một .pptx tệp:

#include <Aspose/Slides/Foss/auto_shape.h>
#include <Aspose/Slides/Foss/export/save_format.h>
#include <Aspose/Slides/Foss/presentation.h>
#include <Aspose/Slides/Foss/shape_collection.h>
#include <Aspose/Slides/Foss/shape_type.h>
#include <Aspose/Slides/Foss/slide.h>
#include <Aspose/Slides/Foss/slide_collection.h>
#include <Aspose/Slides/Foss/text_frame.h>

#include <iostream>

using namespace Aspose::Slides::Foss;

int main() {
    Presentation pres;
    auto& slide = pres.slides()[0];

    // Add a rectangle shape and set its text
    auto& shape = slide.shapes().add_auto_shape(ShapeType::RECTANGLE, 50, 50, 400, 150);
    shape.text_frame()->set_text("Hello from Aspose.Slides FOSS!");

    pres.save("hello.pptx", SaveFormat::PPTX);
    std::cout << "Saved hello.pptx" << std::endl;
    return 0;
}

Quan trọng: Presentation sử dụng RAII. Khi đối tượng ra khỏi phạm vi, các tài nguyên nội bộ được giải phóng tự động. Bạn cũng có thể gọi pres.dispose() một cách rõ ràng nếu cần; việc gọi nó nhiều lần là an toàn.


Ghi chú nền tảng

Windows, macOS, Linux: Thư viện được biên dịch giống hệt trên mọi nền tảng. Không có đường dẫn mã hay phần mở rộng nhị phân đặc thù cho nền tảng nào.

Docker / CI: Sao chép hoặc lấy kho trong bước xây dựng của bạn và chạy CMake. Không cần gói hệ thống bổ sung nào ngoài trình biên dịch C++20 và CMake.

vcpkg / Conan: Hiện chưa được phát hành trên vcpkg hoặc Conan. Thay vào đó, sử dụng FetchContent hoặc git submodule.


Tài nguyên bổ sung

 Tiếng Việt