To add Text into PDF File, we’ll use Aspose.PDF for C++ API, which is a feature-rich, powerful, and easy-to-use document manipulation API for the C++ platform. Open NuGet package manager, search for Aspose.PDF.Cpp and install. You may also use the following command from the Package Manager Console.
PM > Install-Package Aspose.PDF.Cpp
Add Text to PDF File via C++
You need Aspose.PDF for C++ to try the code in your environment.
- Load the PDF with an instance of Document.
- Create a TextParagraph and define its properties.
- Add the TextParagraph to Page using TextBuilder.
- Save the file again.
Add Text to PDF - C++
// Load the PDF file
auto document = MakeObject<Document>(_dataDir + inputFileName);
// get particular page
auto pdfPage = document->get_Pages()->idx_get(1);
// create text fragment
auto textFragment = MakeObject<TextFragment>("Aspose.PDF");
textFragment->set_Position(MakeObject<Position>(80, 700));
// set text properties
textFragment->get_TextState()->set_Font(FontRepository::FindFont(u"Verdana"));
textFragment->get_TextState()->set_FontSize(14);
textFragment->get_TextState()->set_ForegroundColor(Color::get_Blue());
textFragment->get_TextState()->set_BackgroundColor(Color::get_LightGray());
// create TextBuilder object
auto textBuilder = MakeObject<TextBuilder>(pdfPage);
// append the text fragment to the PDF page
textBuilder->AppendText(textFragment);
// Save resulting PDF document.
document->Save(_dataDir + outputFileName);