通過C++從PDF中提取圖像

C++ 庫,用於使用自己的API從PDF中提取圖像。

使用 C++ 庫從 PDF 文件中提取圖像

為了在PDF中添加圖像,我們將使用[Aspose.PDF for C++](https://products.aspose.com/pdf/cpp)API,這是一個功能豐富,功能強大且易於使用的文檔操作API,適用於 cpp 平臺。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf) 包管理器,搜索“.PDF”並安裝。您也可以從程式包管理器主控台使用以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

通過C++從PDF中提取圖像


您需要為C++.PDF [Aspose https://releases.aspose.com/pdf/cpp) 才能在您的環境中嘗試代碼。

  1. 開啟 PDF 文件。
  2. 提取特定圖像。 保存輸出圖像。
  3. 儲存更新的 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");