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

Aspose.PDF FOSS for C++

Open-source C++ library for creating, editing, and rendering 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, and pages are rendered to raster images via device classes such as PngDevice, JpegDevice, BmpDevice, and TiffDevice. Do not rely on releases 1.0.1 or 26.11 to protect confidential documents or to read password-protected ones. Interactive form fields are managed through the Form class, and annotations — text notes, highlights, shapes, and stamps — are created 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 with CMake — build and install it, then locate it from your project with find_package() — 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

  • Document.Encrypt(), Document.Decrypt() and the CryptoAlgorithm enum are part of the API

Important limitation

  • Do not rely on releases 1.0.1 or 26.11 to protect confidential documents or to read password-protected ones

Annotations and Interactive Forms

  • Add annotations through Annotation and AnnotationCollection (flattening needs release 26.11, which also saves text, author, subject and color changes to loaded ones)
  • Manage AcroForm fields through the Form class
  • Add and remove fields with Form.Add()/Form.Delete()
  • Flatten interactive forms with Form.Flatten() (release 26.11 keeps the field values; releases 1.0.x remove them)

Typical use cases

  • Add review comments and highlights to shared PDFs
  • Build fillable PDF forms for data collection
  • Flatten submitted forms before archival (release 26.11 or later)
  • Programmatically pre-fill form fields (saving read-only changes to existing fields needs release 26.11)

Open a PDF, Extract Text, and Render a Page

Build and install the library as described in the installation guide, link it from your CMake project, then open a document, count its pages, extract text with TextAbsorber, and render page 1 to PNG at 150 DPI.

find_package(aspose_pdf_foss CONFIG REQUIRED)
target_link_libraries(your_app PRIVATE aspose_pdf_foss::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);
}

Read and Update Document Metadata

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

Releases 1.0.x: saving metadata changes to a file that has no /Info dictionary throws an exception. Release 26.11 creates the dictionary.

#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.

Can I use it to protect confidential PDF documents?

No. Do not rely on releases 1.0.1 or 26.11 to protect confidential documents or to read password-protected ones.

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

 English