Quick Start

Quick Start

This page shows the minimal code to open a PDF, extract its text, and render a page to a raster image using Document, TextAbsorber, and a device class.


Prerequisites

Before running the examples, complete Installation.


Open a PDF, Extract Text, and Render a Page

Open a document, print its page count, extract all text with Aspose::Pdf::Text::TextAbsorber, and render page 1 to a JPEG at 150 DPI with JpegDevice:

#include <aspose/pdf/document.hpp>
#include <aspose/pdf/page_collection.hpp>
#include <aspose/pdf/text_absorber.hpp>
#include <aspose/pdf/jpeg_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::JpegDevice jpeg(Aspose::Pdf::Devices::Resolution(150));
    std::ofstream out("page1.jpg", std::ios::binary);
    jpeg.Process(doc.Pages()[1], out);
}

TextAbsorber::Visit accepts either the whole Document or a single Page. {Device}::Process takes a page and an output stream — the same pattern applies to BmpDevice and TiffDevice.


Locate Individual Text Fragments

Aspose::Pdf::Text::TextFragmentAbsorber returns positioned text fragments instead of a single flat string, useful when you need per-fragment location or count:

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

Aspose::Pdf::Document doc("input.pdf");
Aspose::Pdf::Text::TextFragmentAbsorber fragmentAbsorber;
fragmentAbsorber.Visit(doc);
std::cout << "Fragments: " << fragmentAbsorber.TextFragments().Count() << "\n";

Read Document Metadata

Document::Info() returns a DocumentInfo with typed accessors for the standard /Info dictionary entries:

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

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

Next Steps

See Also