将PowerPoint PPT转换为JPG

将演示文稿转换为一组图像

在某些情况下,有必要将整个演示文稿转换为一组图像,就像PowerPoint允许的那样。以下C++代码显示了如何将演示文稿转换为JPG图像:

auto imageScale = 1.0f;

auto pres = System::MakeObject<Presentation>(u"PowerPoint-Presentation.ppt");

for (auto&& slide : pres->get_Slides())
{
    // 创建全尺寸图像
    System::SharedPtr<IImage> image = slide->GetImage(imageScale, imageScale);

    // 将图像以JPEG格式保存到磁盘
    auto imageFileName = System::String::Format(u"Slide_{0}.jpg", slide->get_SlideNumber());
    image->Save(imageFileName, ImageFormat::Jpeg);

    image->Dispose();
}

pres->Dispose();

将PowerPoint PPT/PPTX转换为具有自定义尺寸的JPG

要更改生成的缩略图和JPG图像的尺寸,您可以通过将其传递给float scaleX, float YISlide::GetImage()方法来设置ScaleXScaleY值:

auto pres = System::MakeObject<Presentation>(u"PowerPoint-Presentation.pptx");

// 定义尺寸
int32_t desiredX = 1200, desiredY = 800;

// 获取X和Y的缩放值
float scaleX = (float)(1.0 / pres->get_SlideSize()->get_Size().get_Width()) * desiredX;
float scaleY = (float)(1.0 / pres->get_SlideSize()->get_Size().get_Height()) * desiredY;

for (auto&& slide : pres->get_Slides())
{
    // 创建全尺寸图像
    System::SharedPtr<IImage> image = slide->GetImage(scaleX, scaleY);

    // 将图像以JPEG格式保存到磁盘
    auto imageFileName = System::String::Format(u"Slide_{0}.jpg", slide->get_SlideNumber());
    image->Save(imageFileName, ImageFormat::Jpeg);

    image->Dispose();
}

pres->Dispose();

另见

查看其他将PPT/PPTX转换为图像的选项,例如: