Class PdfExtractor
Представляет компонент Documentize.PdfExtractor. Используется для извлечения текста, изображений, данных форм, свойств (метаданных) из PDF‑документов.
public static class PdfExtractorНаследование
Унаследованные члены
- object.GetType(),
- object.MemberwiseClone(),
- object.ToString(),
- object.Equals(object?),
- object.Equals(object?, object?),
- object.ReferenceEquals(object?, object?),
- object.GetHashCode()
Методы
Extract(ExtractTextOptions)
Извлекает текст из PDF‑документа.
public static string Extract(ExtractTextOptions options)Параметры
optionsExtractTextOptions: Объект параметров, содержащий инструкции для операции.
Возвращаемое значение
string : Извлечённый текст.
Примеры
Пример демонстрирует, как извлечь текстовое содержание из PDF‑файла.
// 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);Пример демонстрирует, как извлечь текстовое содержание из PDF‑потока.
// 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);Пример демонстрирует, как извлечь текстовое содержание PDF‑документа с указанием 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);Пример демонстрирует, как извлечь текст из PDF‑файла в самом кратком виде.
// Perform the process and get the extracted text
var textExtracted = PdfExtractor.Extract(new ExtractTextOptions("path_to_your_pdf_file.pdf", TextFormattingMode.Pure));Исключения
Если параметры не заданы.
Extract(ExtractImagesOptions)
Извлекает изображения из PDF‑документа.
public static ResultContainer Extract(ExtractImagesOptions options)Параметры
optionsExtractImagesOptions: Объект параметров, содержащий инструкции для операции.
Возвращаемое значение
ResultContainer : Объект, содержащий результат операции.
Примеры
Пример демонстрирует, как извлечь изображения из PDF‑документа.
// 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();Пример демонстрирует, как извлечь изображения из PDF‑документа в потоки без создания папки.
// 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);
}Исключения
Если параметры не заданы.
Extract(ExtractFormDataToDsvOptions)
Извлекает данные форм из PDF‑документа.
public static ResultContainer Extract(ExtractFormDataToDsvOptions options)Параметры
optionsExtractFormDataToDsvOptions: Объект параметров, содержащий инструкции для операции.
Возвращаемое значение
ResultContainer : Объект, содержащий результат операции.
Примеры
Пример демонстрирует, как экспортировать значения форм в CSV‑файл.
// 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);Пример демонстрирует, как экспортировать значения форм в TSV‑файл и задать свойства.
// 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);Исключения
Если параметры не заданы.
Extract(ExtractPropertiesOptions)
Извлекает свойства из PDF‑документа.
public static PdfProperties Extract(ExtractPropertiesOptions options)Параметры
optionsExtractPropertiesOptions: Объект параметров, содержащий инструкции для операции.
Возвращаемое значение
PdfProperties : Объект, содержащий результат операции.
Примеры
Пример демонстрирует, как извлечь свойства (FileName, Title, Author, Subject, Keywords, Created, Modified, Application, PDF Producer, Number of Pages) из PDF‑файла.
// 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;Пример демонстрирует, как извлечь свойства (Title, Author, Subject, Keywords, Created, Modified, Application, PDF Producer, Number of Pages) из PDF‑потока.
// 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;Пример демонстрирует, как извлечь свойства из PDF‑файла в самом кратком виде.
// Perform the process and get Properties
var pdfProperties = PdfExtractor.Extract(new ExtractPropertiesOptions("path_to_your_pdf_file.pdf"));Исключения
Если параметры не заданы.
Namespace: Documentize Assembly: Documentize.dll