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);この例は 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));例外
options が設定されていない場合。
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();この例はフォルダーを使用せずにストリームへ画像を抽出する方法を示します。
// 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);
}例外
options が設定されていない場合。
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);例外
options が設定されていない場合。
Extract(ExtractPropertiesOptions)
PDF ドキュメントからプロパティを抽出します。
public static PdfProperties Extract(ExtractPropertiesOptions options)パラメーター
optionsExtractPropertiesOptions: 操作の指示を含むオプション オブジェクト。
戻り値
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 ストリームから同様のプロパティを抽出する方法を示します。
// 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"));例外
options が設定されていない場合。
名前空間: Documentize
アセンブリ: Documentize.dll