Snabb start
Snabb start
Denna guide visar den snabbaste vägen från CMake-inställning till en sparat .pptx filer med användning aspose_slides_foss för C++. biblioteket är MIT-licenserat, kräver inte Microsoft Office, och bygger på någon plattform med en C++20-kompilator och CMake 3.20 eller senare.
Prerequisites
| Requirement | Detail |
|---|---|
| C++ standard | C++20 eller senare |
| CMEKE | 3.20 or later |
| OS | Windows, MacOS och Linux |
| Package | aspose_slides_foss via CMake FetchContent |
Install
Använd CMAK FetchContent att dra biblioteket vid konfigurationstid. Lägg till följande till din CMakeLists.txt och sedan länkar mot aspose_slides_foss:
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)
target_link_libraries(your_target PRIVATE aspose_slides_foss)Skapa en presentation
Construct Presentation med inga argument för att skapa en vit täck, sedan ringa save() med en väg och SaveFormat::PPTX.Biblioteket lägger automatiskt till en tom slide:
#include <Aspose/Slides/Foss/presentation.h>
#include <Aspose/Slides/Foss/export/save_format.h>
using namespace Aspose::Slides::Foss;
int main() {
Presentation prs;
prs.save("empty.pptx", SaveFormat::PPTX);
return 0;
}Lägg till en form med text
Tillgång till den första slidan via prs.slides()[0],Lägg in en rektangel med shapes().add_auto_shape(),och lägga till texten via text_frame()->set_text():
#include <Aspose/Slides/Foss/auto_shape.h>
#include <Aspose/Slides/Foss/presentation.h>
#include <Aspose/Slides/Foss/shape_type.h>
#include <Aspose/Slides/Foss/text_frame.h>
#include <Aspose/Slides/Foss/export/save_format.h>
int main() {
Presentation prs;
auto& slide = prs.slides()[0];
auto& shape = slide.shapes().add_auto_shape(
ShapeType::RECTANGLE, 50, 50, 400, 150
);
shape.text_frame()->set_text("Hello from Aspose.Slides FOSS!");
prs.save("with_shape.pptx", SaveFormat::PPTX);
return 0;
}Applicera en solid fyllning
Call fill_format().set_fill_type(FillType::SOLID) i form och levererar en ArGB färg via solid_fill_color().set_color() Innan du ringer save():
#include <Aspose/Slides/Foss/auto_shape.h>
#include <Aspose/Slides/Foss/fill_format.h>
#include <Aspose/Slides/Foss/fill_type.h>
#include <Aspose/Slides/Foss/presentation.h>
#include <Aspose/Slides/Foss/shape_type.h>
#include <Aspose/Slides/Foss/export/save_format.h>
int main() {
Presentation prs;
auto& shape = prs.slides()[0].shapes().add_auto_shape(
ShapeType::RECTANGLE, 100, 100, 400, 200
);
shape.fill_format().set_fill_type(FillType::SOLID);
shape.fill_format().solid_fill_color().set_color(0xFF, 0x46, 0x82, 0xB4);
shape.text_frame()->set_text("Styled shape");
prs.save("styled.pptx", SaveFormat::PPTX);
return 0;
}Ladda upp en befintlig fil
Passera en filvägssträng till den Presentation Konstruktorn ska ladda en befintlig .pptx fil. Ändra däck som behövs och ringa sedan save() För att skriva utgåvan:
#include <Aspose/Slides/Foss/presentation.h>
#include <Aspose/Slides/Foss/export/save_format.h>
int main() {
Presentation prs("existing.pptx");
prs.save("copy.pptx", SaveFormat::PPTX);
return 0;
}