Aspose.PDF  for C++

Search PDF Formats in C++

Native and high performance PDF document search using server-side Aspose.PDF for C++ APIs, without the use of any software like Microsoft or Adobe PDF.

How to Search PDF File Using C++

In order to search 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 Command

                                PM> Install-Package Aspose.PDF.Cpp

Search PDF File via C++

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

  1. Load the PDF with an instance of Document.
  2. Create TextFragmentAbsorber Object with text to find as parameter.
  3. Get all extracted text fragments collection.
  4. Loop through each fragment to get all of its information.

System Requirements

Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with C++ Runtime Environment for Windows 32 bit, Windows 64 bit, and Linux 64 bit.
  • Development environment like Microsoft Visual Studio.
  • Aspose.PDF for C++ DLL referenced in your project.

Search PDF Files - C++.

// Load PDF document
Document pdfDocument = new Document("source.pdf");

// Create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("\d{4}-\d{4}"); // like 1999-2000

// Set text search option to specify regular expression usage
TextSearchOptions textSearchOptions = new TextSearchOptions(true);

// Accept the absorber for first page of document

// Get the extracted text fragments into collection
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();

// Loop through the fragments
for (TextFragment textFragment : (Iterable<TextFragment>) textFragmentCollection) {
	System.out.println("Text :- " + textFragment.getText());
	System.out.println("Position :- " + textFragment.getPosition());
	System.out.println("XIndent :- " + textFragment.getPosition().getXIndent());
	System.out.println("YIndent :- " + textFragment.getPosition().getYIndent());
	System.out.println("Font - Name :- " + textFragment.getTextState().getFont().getFontName());
	System.out.println("Font - IsAccessible :- " + textFragment.getTextState().getFont().isAccessible());
	System.out.println("Font - IsEmbedded - " + textFragment.getTextState().getFont().isEmbedded());
	System.out.println("Font - IsSubset :- " + textFragment.getTextState().getFont().isSubset());
	System.out.println("Font Size :- " + textFragment.getTextState().getFontSize());
	System.out.println("Foreground Color :- " + textFragment.getTextState().getForegroundColor());

About Aspose.PDF for C++ API

Aspose.PDF API can be used for PDF document manipulation and parsing within applications. One can create, modify, compress, secure, print or save PDF to TXT, HTML, PCL, XFA, XML, XPS, EPUB, TEX, Images and more formats. Aspose.PDF is a standalone API and it does not depend on any software including Adobe Acrobat.

Online PDF Search Live Demos