1. Products
  2.   Aspose.PDF
  3.   Aspose.PDF FOSS for C++

Aspose.PDF FOSS for C++

Open-source C++ library for creating, editing, rendering, and securing PDF documents with zero runtime dependencies.

Aspose.PDF FOSS — Open Source C++ PDF Library

Aspose.PDF FOSS for C++ is an open-source, modern C++20 library for working with PDF documents — opening and saving PDFs, extracting text, rasterising pages to image formats, and building documents from scratch (text, images, tables, vector graphics, annotations, AcroForm fields, and bookmarks). The library links against nothing but the C++ standard library: every primitive, including the TIFF, JPEG, and PNG codecs and the page rasteriser, is implemented from scratch with no dependency on any commercial PDF stack.

The core API is built around the Document class and its Pages() collection. Text is extracted with Aspose::Pdf::Text::TextAbsorber, pages are rendered to raster images via device classes such as PngDevice, JpegDevice, BmpDevice, and TiffDevice, and documents can be secured with Document.Encrypt() using RC4-40, RC4-128, AES-128, or AES-256 algorithms selected through the CryptoAlgorithm enum. Interactive form fields are managed through the Form class, and annotations — text notes, highlights, shapes, and stamps — are added and modified through the Annotation class hierarchy.

Aspose.PDF FOSS for C++ is released under the MIT license with no runtime fees or usage restrictions. It builds as a static library via CMake — add it as a subdirectory of your build or install it standalone — and requires a C++20 compiler with no other runtime dependencies. For enterprise features and support, see Aspose.PDF for C++ — Enterprise Product.

Document Loading and Page Management

  • Open existing PDF files and save modifications with Document
  • Access and iterate pages via Document.Pages() (PageCollection)
  • Add, insert, and delete pages with PageCollection.Add()/Insert()/Delete()
  • Read and set document metadata through DocumentInfo (Document.Info())
  • Optimize document size with Document.Optimize()/OptimizeResources()

Typical use cases

  • Build PDF generation pipelines for reports and invoices
  • Merge, split, and reorganize existing PDF documents
  • Programmatically inspect and update document metadata
  • Reduce PDF file size before archival or distribution

Text Extraction

  • Extract plain text from an entire document with Aspose::Pdf::Text::TextAbsorber
  • Visit a single page or the whole document via TextAbsorber.Visit()
  • Retrieve extracted text through TextAbsorber.Text()
  • Locate individual text fragments with TextFragmentAbsorber.TextFragments()

Typical use cases

  • Index PDF content for search
  • Extract data from invoices and structured documents
  • Build text-mining or content-analysis pipelines
  • Verify document content in automated test suites

Rendering to Raster Images

  • Render pages to PNG with PngDevice
  • Render pages to JPEG, BMP, or TIFF with JpegDevice, BmpDevice, TiffDevice
  • Control output resolution with the Resolution class
  • Process a single page via {Device}.Process()

Typical use cases

  • Generate page thumbnails for a document viewer
  • Produce print-ready raster output from vector PDFs
  • Build PDF-to-image conversion services
  • Create visual regression baselines for generated PDFs

Encryption and Security

  • Encrypt documents with Document.Encrypt() using a user and owner password
  • Choose RC4-40, RC4-128, AES-128, or AES-256 via the CryptoAlgorithm enum
  • Control granted permissions with the Permissions type
  • Decrypt password-protected documents with Document.Decrypt()

Typical use cases

  • Protect confidential PDF reports before distribution
  • Enforce print/copy/edit restrictions on shared documents
  • Add password protection to generated invoices and statements
  • Batch-encrypt documents as part of a document pipeline

Annotations and Interactive Forms

  • Add, modify, and flatten annotations through Annotation and AnnotationCollection
  • Manage AcroForm fields through the Form class
  • Add and remove fields with Form.Add()/Form.Delete()
  • Flatten interactive forms to static content with Form.Flatten()

Typical use cases

  • Add review comments and highlights to shared PDFs
  • Build fillable PDF forms for data collection
  • Flatten submitted forms before archival
  • Programmatically pre-fill and lock form fields

Open a PDF, Extract Text, and Render a Page

Add the library as a CMake subdirectory, then open a document, count its pages, extract text with TextAbsorber, and render page 1 to PNG at 150 DPI.

add_subdirectory(aspose.pdf-foss-for-cpp)
target_link_libraries(your_app PRIVATE aspose_pdf_foss)
#include <aspose/pdf/document.hpp>
#include <aspose/pdf/page_collection.hpp>
#include <aspose/pdf/text_absorber.hpp>
#include <aspose/pdf/png_device.hpp>
#include <aspose/pdf/resolution.hpp>
#include <fstream>
#include <iostream>

int main() {
    Aspose::Pdf::Document doc("input.pdf");
    std::cout << "Pages: " << doc.Pages().Count() << "\n";

    Aspose::Pdf::Text::TextAbsorber absorber;
    absorber.Visit(doc);
    std::cout << absorber.Text() << "\n";

    Aspose::Pdf::Devices::PngDevice png(Aspose::Pdf::Devices::Resolution(150));
    std::ofstream out("page1.png", std::ios::binary);
    png.Process(doc.Pages()[1], out);
}

Encrypt a Document with AES-256

Open a document and protect it with a user and owner password using AES-256 encryption.

#include <aspose/pdf/document.hpp>
int main() {
    Aspose::Pdf::Document doc("input.pdf");
    doc.Encrypt("user-password", "owner-password",
                Aspose::Pdf::Permissions(),
                Aspose::Pdf::CryptoAlgorithm::AESx256);
    doc.Save("encrypted.pdf");
}

Read and Update Document Metadata

Read existing /Info entries and update the document title through DocumentInfo.

#include <aspose/pdf/document.hpp>
#include <aspose/pdf/document_info.hpp>
#include <iostream>

int main() {
    Aspose::Pdf::Document doc("input.pdf");
    auto& info = doc.Info();
    std::cout << "Title: " << info.Title() << "\n";
    std::cout << "Author: " << info.Author() << "\n";

    doc.SetTitle("Updated Report Title");
    doc.Save("output.pdf");
}

Frequently Asked Questions

What is the licensing model for Aspose.PDF FOSS for C++?

It is MIT-licensed and free to use in commercial and non-commercial products, with no activation key or API call limits.

What compiler and CMake versions are required?

A C++20 compiler (clang 16+, gcc 13+, or MSVC 2022 17.5+) and CMake 3.22 or later. Python 3 is required at build time only.

Does the library have any runtime dependencies?

No. It links against nothing but the C++ standard library — no third-party PDF, image, or compression dependency is required at runtime.

Which formats can it read and export?

It reads and saves native PDF documents, and exports rendered pages to Bmp, Jpeg, and Tiff, plus plain text. SVG content can be imported.

How do I encrypt a PDF document?

Call Document.Encrypt() with a user password, an owner password, and a CryptoAlgorithm (RC4x40, RC4x128, AESx128, or AESx256).

Are there any known limitations in the current release?

Yes — a few XmpValue type-checking helpers (IsDateTime, IsField, and similar) are stubs that always return false; use IsString/IsInteger/IsDouble/IsArray instead.

  

Support and Learning Resources