On this page
Guides
Data Extraction Guides
Unleash the Power of Data with ComPDFKit Conversion SDK's Data Extraction to detect, recognize, analyze, and extract the PDF text, text structure, table, etc.
Extract Text from PDF
Overview
To extract text content from a PDF document.
Notice
- Disabling OCR (Optical Character Recognition) can result in the inability to extract text from tables within images.
- When we use the
CPDFConverterJson
class to access the content streams from a PDF document, we are often faced with fragmented data. For example, let us say that we are attempting to extract a sentence that says "This is a sample sentence." from a PDF document. You may end up retrieving parts of it as separate content streams like "This" and "is a sample sentence.". This occurs because text objects in PDF are not always cleanly organized into words sentences, or paragraphs. When OCR is unenabled, theCPDFConverterJson
class will return Text objects exactly as they are defined in the PDF page content streams.
Sample
Full sample code which illustrates the text extraction capabilities.
objective-c
// Get the path of the PDF file.
NSString *pdfPath = @"...";
// Get the path to the json file.
NSString *outputPath = @"...";
CPDFConvertJsonOptions *options = [[CPDFConvertJsonOptions alloc] init];
CPDFConverterJson *converter = [[CPDFConverterJson alloc] initWithURL:[NSURL fileURLWithPath:pdfPath] password:nil];
[converter convertToFilePath:outputPath pageIndexs:nil options:options];