Button Fields and Images in C++

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

Add image appearance to button field

Fill the Image1_af_image button image field from an image stream.

  1. Create Form.
  2. Bind the PDF input with Facade::BindPdf().
  3. Set the field image appearance with Form::FillImageField().
  4. Save the resulting PDF with Form::Save().
#include <Aspose.PDF.Cpp/Facades/Form.h>
#include <system/io/file.h>
#include <system/io/file_stream.h>
#include <system/string.h>

namespace Facades::Examples::PDF_Form
{
	using namespace System;
	using namespace Aspose::Pdf;
	using namespace Aspose::Pdf::Facades;
	using Form = Aspose::Pdf::Facades::Form;

	void AddImageAppearanceToButtonField(String inputFile, String imageFile, String outputFile)
	{
		auto form = MakeObject<Form>();
		auto imageStream = System::IO::File::OpenRead(imageFile);

		form->Facade::BindPdf(inputFile);
		form->FillImageField(u"Image1_af_image", imageStream);
		form->Save(outputFile);
	}
} // namespace Facades::Examples::PDF_Form