通过 C++ 从 PDF 中提取图像

C++ 使用自己的 API 从 PDF 中提取图像的库。

使用 C++ 库从 PDF 文档中提取图像

为了在 PDF 中添加 Image,我们将使用 Aspose.PDF for C++ API,这是一款适用于 cpp 平台的功能丰富、功能强大且易于使用的文档处理 API。打开 NuGet 软件包管理器,搜索 aspose.pdf 然后安装。您也可以在软件包管理器控制台中使用以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

通过 C++ 从 PDF 中提取图像


你需要 Aspose.PDF for C++ 才能在你的环境中试用代码。

1。打开 PDF 文档。 1。提取特定的图像。 1。保存输出图像。 1。保存更新后的 PDF 文件。

从 PDF 文件中提取图像-C++。

<% images-extract.code-block.subtitle %>


    // Open document
    auto document = MakeObject<Document>(_dataDir + u"ExtractImages.pdf");

    // Extract a particular image
    auto xImage = document->get_Pages()->idx_get(1)->get_Resources()->get_Images()->idx_get(1);

    auto outputImage = System::IO::File::OpenWrite(_dataDir + u"output.jpg");

    // Save output image
    xImage->Save(outputImage, System::Drawing::Imaging::ImageFormat::get_Jpeg());
    outputImage->Close();

    // Save updated PDF file
    document->Save(_dataDir + u"ExtractImages_out.pdf");