String _dataDir("C:\\Samples\\");
auto document = MakeObject<Document>(_dataDir + u"AddImage.pdf");
int lowerLeftX = 50;
int lowerLeftY = 750;
int upperRightX = 100;
int upperRightY = 800;
auto page = document->get_Pages()->idx_get(1);
auto imageStream = System::IO::File::OpenRead(_dataDir + u"logo.png");
page->get_Resources()->get_Images()->Add(imageStream);
page->get_Contents()->Add(MakeObject<Aspose::Pdf::Operators::GSave>());
auto rectangle = MakeObject<Rectangle>(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
auto matrix = MakeObject<Matrix>(
MakeArray<double>({
rectangle->get_URX() - rectangle->get_LLX(),
0, 0,
rectangle->get_URY() - rectangle->get_LLY(),
rectangle->get_LLX(), rectangle->get_LLY() }));
page->get_Contents()->Add(MakeObject<Aspose::Pdf::Operators::ConcatenateMatrix>(matrix));
auto ximage = page->get_Resources()->get_Images()->idx_get(page->get_Resources()->get_Images()->get_Count());
page->get_Contents()->Add(MakeObject<Aspose::Pdf::Operators::Do>(ximage->get_Name()));
page->get_Contents()->Add(MakeObject<Aspose::Pdf::Operators::GRestore>());
document->Save(_dataDir + u"updated_document.pdf");
imageStream->Close();