Edit PDF via C++

Advanced PDF Editor for C++. Use Aspose.PDF to modify PDF documents programmatically

How to Edit PDF with C++

Do you need to edit PDF? Programmatic modification of PDF documents is an essential part of modern digital workflows. With C++ libraries like Aspose.PDF, developers can edit text in PDF, insert graphs using external data, modify tables and more. These libraries are stand-alone solutions that don’t rely on other software and are ready for commercial use. They cover all possible needs of professional C++ developers.

  • Edit PDF elements: tables, texts, images,, fields, etc.
  • Edit PDF formatting attributes and styles
  • Add new elements
  • Work with graphs and forms

In order to to edit PDF file, we’ll use Aspose.PDF for C++ API which is a feature-rich, powerful and easy to use document manipulation API for cpp platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

How to Edit PDF via C++


You need Aspose.PDF for C++ to try the code in your environment.

  1. Design and Develop your editor.
  2. Or use Aspose Editor by accessing its demo app using advanced WYSIWYG editor.
  3. Upload PDF files to edit.
  4. Modify the document with relevant changes.
  5. Save the PDF file.

One of the most requested features is the editing and adding text in PDF. Working with text is very convenient with C++ library: edit text, update text and format text using C++. The following example demostrates how to modify a PDF document in C++:

Edit PDF Files - C++

This sample code shows how to edit text in PDF - C++

	void ReplaceTextInParticularRegion() {

    String _dataDir("C:\\Samples\\");

    // load PDF file
    auto document = MakeObject<Document>(_dataDir + u"sample.pdf");

    // instantiate TextFragment Absorber object
    auto textFragmentAbsorber = MakeObject<TextFragmentAbsorber>("PDF");

    // search text within page bound
    textFragmentAbsorber->get_TextSearchOptions()->set_LimitToPageBounds(true);

    // specify the page region for TextSearch Options
    textFragmentAbsorber->get_TextSearchOptions()->set_Rectangle(new Rectangle(100, 700, 400, 770));

    // search text from first page of PDF file
    document->get_Pages()->idx_get(1)->Accept(textFragmentAbsorber);

    // iterate through individual TextFragment
    for (auto tf : textFragmentAbsorber->get_TextFragments()) {
        // replace text with "---"
        tf->set_Text(u"---");
    }

    // Save the updated PDF file
    document->Save(_dataDir + u"Updated_Text.pdf");
}

About Aspose.PDF for C++ API

Aspose.PDF for C++ is a powerful processing library that enables developers to create, read and manipulate PDF documents without using Adobe Acrobat. It provides a wide range of features such as creating forms, adding/editing text, manipulating PDF pages, adding annotations, handling custom fonts and much more.

Aspose.PDF for C++ is a library that enables the developers to add PDF processing capabilities to their applications. API can be used to build any type of 32-bit and 64-bit applications to generate or read, convert and manipulate PDF files without the use of Adobe Acrobat.

You can find detailed explanation & examples for every class & method in Aspose.PDF for C++ library in the API reference. And also recommend to view a Documentation.