Class PdfExtractor

Info

Represents Documentize.PdfExtractor plugin. Used to Extract Text, Images, Form Data, Properties (Meta Data) from PDF documents.

public static class PdfExtractor

Inheritance

objectPdfExtractor

Inherited Members

Methods

Extract(ExtractTextOptions)

Extract Text from PDF document.

public static string Extract(ExtractTextOptions options)

Parameters

Returns

string : Extracted Text.

Examples

The example demonstrates how to Extract Text content from PDF file.

// Create ExtractTextOptions object to set input file path
var options = new ExtractTextOptions("path_to_your_pdf_file.pdf");
// Perform the process and get the extracted text
var textExtracted = PdfExtractor.Extract(options);

The example demonstrates how to Extract Text content from PDF stream.

// Create ExtractTextOptions object to set input stream
var stream = File.OpenRead("path_to_your_pdf_file.pdf");
var options = new ExtractTextOptions(stream);
// Perform the process and get the extracted text
var textExtracted = PdfExtractor.Extract(options);

The example demonstrates how to Extract Text content of PDF document with TextFormattingMode.

// Create ExtractTextOptions object to set input file path and TextFormattingMode
var options = new ExtractTextOptions("path_to_your_pdf_file.pdf", TextFormattingMode.Pure);
// Perform the process and get the extracted text
var textExtracted = PdfExtractor.Extract(options);

The example demonstrates how to Extract Text from PDF file in the shortest possible style.

// Perform the process and get the extracted text
var textExtracted = PdfExtractor.Extract(new ExtractTextOptions("path_to_your_pdf_file.pdf", TextFormattingMode.Pure));

Exceptions

ArgumentException

If options not set.

Extract(ExtractImagesOptions)

Extract images from PDF document.

public static ResultContainer Extract(ExtractImagesOptions options)

Parameters

Returns

ResultContainer : An object containing the result of the operation.

Examples

The example demonstrates how to Extract Images from PDF document.

// Create ExtractImagesOptions to set instructions
var options = new ExtractImagesOptions();
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryData("path_to_results_directory"));
// Perform the process
var results = PdfExtractor.Extract(options);
// Get path to image result
var imageExtracted = results.ResultCollection[0].ToFile();

The example demonstrates how to Extract Images from PDF document to Streams without folder.

// Create ExtractImagesOptions to set instructions
var options = new ExtractImagesOptions();
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Not set output - it will write results to streams
// Perform the process
var results = PdfExtractor.Extract(options);
// Get Stream
var ms = results.ResultCollection[0].ToStream();
// Copy data to file for demo
ms.Seek(0, SeekOrigin.Begin);
using (var fs = File.Create("test_file.png"))
{
    ms.CopyTo(fs);
}

Exceptions

ArgumentException

If options not set.

Extract(ExtractFormDataToDsvOptions)

Extract Form Data from PDF document.

public static ResultContainer Extract(ExtractFormDataToDsvOptions options)

Parameters

Returns

ResultContainer : An object containing the result of the operation.

Examples

The example demonstrates how to Export Form values to CSV file.

// Create ExtractFormDataToDsvOptions object to set instructions
var options = new ExtractFormDataToDsvOptions(',', true);
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_csv_file.csv"));
// Perform the process
PdfExtractor.Extract(options);

The example demonstrates how to Export Form values to TSV file and set Properties.

// Create ExtractFormDataToDsvOptions object to set instructions
var options = new ExtractFormDataToDsvOptions();
//Set Delimiter
options.Delimiter = '\t';
//Add Field Names to result
options.AddFieldName = true;
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_csv_file.tsv"));
// Perform the process
PdfExtractor.Extract(options);

Exceptions

ArgumentException

If options not set.

Extract(ExtractPropertiesOptions)

Extract Properties from PDF document.

public static PdfProperties Extract(ExtractPropertiesOptions options)

Parameters

Returns

PdfProperties : An object containing the result of the operation.

Examples

The example demonstrates how to Extract Properties (FileName, Title, Author, Subject, Keywords, Created, Modified, Application, PDF Producer, Number of Pages) from PDF file.

// Create ExtractPropertiesOptions object to set input file
var options = new ExtractPropertiesOptions("path_to_your_pdf_file.pdf");
// Perform the process and get Properties
var pdfProperties = PdfExtractor.Extract(options);
var filename = pdfProperties.FileName;
var title = pdfProperties.Title;
var author = pdfProperties.Author;
var subject = pdfProperties.Subject;
var keywords = pdfProperties.Keywords;
var created = pdfProperties.Created;
var modified = pdfProperties.Modified;
var application = pdfProperties.Application;
var pdfProducer = pdfProperties.PdfProducer;
var numberOfPages = pdfProperties.NumberOfPages;

The example demonstrates how to Extract Properties (Title, Author, Subject, Keywords, Created, Modified, Application, PDF Producer, Number of Pages) from PDF stream.

// Create ExtractPropertiesOptions object to set input stream
var stream = File.OpenRead("path_to_your_pdf_file.pdf");
var options = new ExtractPropertiesOptions(stream);
// Perform the process and get Properties
var pdfProperties = PdfExtractor.Extract(options);
var title = pdfProperties.Title;
var author = pdfProperties.Author;
var subject = pdfProperties.Subject;
var keywords = pdfProperties.Keywords;
var created = pdfProperties.Created;
var modified = pdfProperties.Modified;
var application = pdfProperties.Application;
var pdfProducer = pdfProperties.PdfProducer;
var numberOfPages = pdfProperties.NumberOfPages;

The example demonstrates how to Extract Properties from PDF file in the shortest possible style.

// Perform the process and get Properties
var pdfProperties = PdfExtractor.Extract(new ExtractPropertiesOptions("path_to_your_pdf_file.pdf"));

Exceptions

ArgumentException

If options not set.

Namespace: Documentize Assembly: Documentize.dll

 English