Replace Text With State in C++

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

Replace text with state

Replace software with SOFTWARE using blue, 14-point text and ReplaceAll scope.

  1. Configure text appearance through TextState.
  2. Create PdfContentEditor.
  3. Bind the PDF input with Facade::BindPdf().
  4. Replace matching text with PdfContentEditor::ReplaceText().
  5. Save the resulting PDF with PdfContentEditor::Save().
#include <Aspose.PDF.Cpp/Color.h>
#include <Aspose.PDF.Cpp/Facades/PdfContentEditor.h>
#include <Aspose.PDF.Cpp/Facades/ReplaceTextStrategy.h>
#include <Aspose.PDF.Cpp/Text/TextState.h>
#include <system/string.h>

namespace Facades::Examples::PDF_ContentEditor
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;
using namespace Aspose::Pdf::Text;
using PdfColor = Aspose::Pdf::Color;

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

    editor->BindPdf(inputFile);
    auto textState = MakeObject<TextState>();
    textState->set_ForegroundColor(PdfColor::get_Blue());
    textState->set_FontSize(14);
    editor->get_ReplaceTextStrategy()->set_ReplaceScope(ReplaceTextStrategy::Scope::ReplaceAll);
    editor->ReplaceText(u"software", u"SOFTWARE", textState);
    editor->Save(outputFile);
}
} // namespace Facades::Examples::PDF_ContentEditor