Skip to content
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, image, 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 CPDFConverterJsonText 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, the CPDFConverterJsonText 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.

c#
string inputFilePath = "***";
string outputFolderPath = "***";
string outputFileName = "***";

CPDFConverterJsonText converter = CPDFConvertFactroy.CreateConverter(CPDFConvertType.CPDFConvertTypeJsonText, inputFilePath) as CPDFConverterJsonText;

CPDFConvertJsonOptions jsonOptions = new CPDFConvertJsonOptions();
jsonOptions.IsAllowOCR = false;

ConvertError error = ConvertError.ERR_UNKNOWN;
jsonTextConverter.Convert(outputFolderPath, ref outputFileName, jsonOptions, ref error);