Class PdfExtractor

情報

Documentize.PdfExtractor コンポーネントを表します。PDF ドキュメントからテキスト、画像、フォームデータ、プロパティ(メタデータ)を抽出するために使用されます。

public static class PdfExtractor

継承

object ← PdfExtractor

継承されたメンバー

メソッド

Extract(ExtractTextOptions)

PDF ドキュメントからテキストを抽出します。

public static string Extract(ExtractTextOptions options)

パラメーター

  • options ExtractTextOptions: 操作の指示を含むオプションオブジェクトです。

戻り値

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);

この例は TextFormattingMode を使用して PDF ドキュメントのテキストコンテンツを抽出する方法を示しています。

// 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));

例外

ArgumentException

options が設定されていない場合。

Extract(ExtractImagesOptions)

PDF ドキュメントから画像を抽出します。

public static ResultContainer Extract(ExtractImagesOptions options)

パラメーター

戻り値

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();

この例はフォルダーを使わずにストリームへ画像を抽出する方法を示しています。

// 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);
}

例外

ArgumentException

options が設定されていない場合。

Extract(ExtractFormDataToDsvOptions)

PDF ドキュメントからフォームデータを抽出します。

public static ResultContainer Extract(ExtractFormDataToDsvOptions options)

パラメーター

戻り値

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);

例外

ArgumentException

options が設定されていない場合。

Extract(ExtractPropertiesOptions)

PDF ドキュメントからプロパティを抽出します。

public static PdfProperties Extract(ExtractPropertiesOptions options)

パラメーター

戻り値

PdfProperties : 操作の結果を含むオブジェクトです。

例

この例は PDF ファイルからプロパティ(FileName、Title、Author、Subject、Keywords、Created、Modified、Application、PDF Producer、ページ数)を抽出する方法を示しています。

// 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;

この例は PDF ストリームからプロパティ(Title、Author、Subject、Keywords、Created、Modified、Application、PDF Producer、ページ数)を抽出する方法を示しています。

// 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"));

例外

ArgumentException

options が設定されていない場合。

名前空間: Documentize アセンブリ: Documentize.dll

 日本語