Replace Images in PDF in C++

Contents
[ ]

Use PdfContentEditor for this task. The examples below retain the original C++ code and API Reference steps.

Replace image

Replace image index 1 on page 1 with imageFile.

  1. Create PdfContentEditor.
  2. Bind the PDF input with Facade::BindPdf().
  3. Replace the selected image with PdfContentEditor::ReplaceImage().
  4. Save the resulting PDF with PdfContentEditor::Save().
#include <Aspose.PDF.Cpp/Facades/PdfContentEditor.h>
#include <system/string.h>

namespace Facades::Examples::PDF_ContentEditor
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;

void ReplaceImage(String inputFile, String imageFile, String outputFile)
{
    auto editor = MakeObject<PdfContentEditor>();

    editor->BindPdf(inputFile);
    editor->ReplaceImage(1, 1, imageFile);
    editor->Save(outputFile);
}
} // namespace Facades::Examples::PDF_ContentEditor