Basic text extraction in C++
Contents
[
Hide
]
Extract text from all pages, the first page, or detected paragraphs using Aspose.PDF for C++.
Extract text from all pages
Collect document text into one output file.
- Open the input PDF as a Document.
- Create a TextAbsorber.
- Pass the absorber to the page collection’s Accept() method.
- Read the absorber’s Text property.
- Write the extracted text to the output file.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/Page.h>
#include <Aspose.PDF.Cpp/PageCollection.h>
#include <Aspose.PDF.Cpp/Text/TextAbsorber.h>
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Text;
void ExtractTextFromAllThePages(System::String path_infile, System::String path_outfile) {
// Open document
auto document = MakeObject<Document>(path_infile);
// Create TextAbsorber object to extract text
auto textAbsorber = MakeObject<TextAbsorber>();
// Accept the absorber for all the pages
document->get_Pages()->Accept(textAbsorber);
// Get the extracted text
auto extractedText = textAbsorber->get_Text();
System::IO::File::WriteAllText(path_outfile, extractedText);
}