Class PdfManager

情報

Documentize.PdfManager コンポーネントを表します。PDF 文書の結合、分割、最適化、回転、サイズ変更、圧縮、および表の追加、目次 (TOC) の追加に使用します。複数の PDF 文書を単一の PDF に結合できます。PDF 文書を個別のページに分割できます。PDF 文書を最適化、回転、サイズ変更、圧縮できます。PDF 文書のページを回転、サイズ変更できます。PDF 文書に表を追加できます。PDF 文書に目次を追加できます。

Documentize.PdfManager コンポーネントを表します。PDF 文書の結合、分割、最適化、回転、サイズ変更、圧縮、および表の追加、目次 (TOC) の追加に使用します。

  • 複数の PDF 文書を単一の PDF に結合できます。
  • PDF 文書を個別のページに分割できます。
  • PDF 文書を最適化、回転、サイズ変更、圧縮できます。
  • PDF 文書のページを回転、サイズ変更できます。
  • PDF 文書に表を追加できます。
  • PDF 文書に目次を追加できます。
public static class PdfManager

継承

object ←
PdfManager

継承されたメンバー

メソッド

AddTable(TableOptions)

PDF 文書に表を追加します。

public static ResultContainer AddTable(TableOptions options)

パラメータ

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

戻り値

ResultContainer: 操作結果を含むオブジェクト。

使用例

この例は PDF ファイルに表を追加する方法を示しています。

// テーブルオプションを設定
var options = new TableOptions();
options.InsertPageBefore(1)
   .AddTable()
        .AddRow()
            .AddCell().AddParagraph("Name")
            .AddCell().AddParagraph("Age")
        .AddRow()
            .AddCell().AddParagraph("Bob")
            .AddCell().AddParagraph("12")
        .AddRow()
            .AddCell().AddParagraph("Sam")
            .AddCell().AddParagraph("20")
        .AddRow()
            .AddCell().AddParagraph("Sandy")
            .AddCell().AddParagraph("26")
        .AddRow()
            .AddCell().AddParagraph("Tom")
            .AddCell().AddParagraph("12")
        .AddRow()
            .AddCell().AddParagraph("Jim")
            .AddCell().AddParagraph("27");
// 入力ファイルパスを追加
options.AddInput(new FileData("path_to_input.pdf"));
// 出力ファイルパスを設定
options.AddOutput(new FileData("path_to_output.pdf"));
// 処理を実行
PdfManager.AddTable(options);

この例は 2 ページ目の前に表を追加する方法を示しています。

// テーブルオプションを設定
var options = new TableOptions();
options.InsertPageBefore(2) // 2 ページ目の前に表を追加
   .AddTable()
        .AddRow()
            .AddCell().AddParagraph("Name")
            .AddCell().AddParagraph("Age");
// 入力ファイルパスを追加
options.AddInput(new FileData("path_to_input.pdf"));
// 出力ファイルパスを設定
options.AddOutput(new FileData("path_to_output.pdf"));
// 処理を実行
PdfManager.AddTable(options);

例外

AddTableOfContents(TocOptions)

PDF 文書に目次 (TOC) を追加します。

public static ResultContainer AddTableOfContents(TocOptions options)

パラメータ

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

戻り値

ResultContainer: 操作結果を含むオブジェクト。

使用例

PDF ファイルに目次を追加する例です。

// TocOptions オブジェクトを作成して指示を設定
var options = new TocOptions();
// タイトルを設定
options.Title = "My Table of Contents";
// 見出しをデザイン
options.Headings.Add(new TocHeading("Introduction", 2));
options.Headings.Add(new TocHeading("Chapter I", 3));
options.Headings.Add(new TocHeading("Chapter II", 4));
options.Headings.Add(new TocHeading("Chapter III", 5));
// 入力ファイルパスを追加
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// 出力ファイルパスを設定
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// 処理を実行
PdfManager.AddTableOfContents(options);

ブックマークを生成しながら目次を追加する例です。

var options = new TocOptions();
options.Title = "My Table of Contents";
options.GenerateBookmarks = true;
options.Headings.Add(new TocHeading("Introduction", 2, false, 1));
options.Headings.Add(new TocHeading("Chapter I", 3, true, 1));
options.Headings.Add(new TocHeading("Chapter II", 4, true, 1));
options.Headings.Add(new TocHeading("Example A", 4, true, 2));
options.Headings.Add(new TocHeading("Example B", 4, true, 2));
options.Headings.Add(new TocHeading("Example C", 4, true, 2));
options.Headings.Add(new TocHeading("Example D", 4, true, 2));
options.Headings.Add(new TocHeading("Chapter III", 5, true, 1));
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.AddTableOfContents(options);

目次をストリームとして保存する例です。

var options = new TocOptions();
options.Title = "My Table of Contents";
options.Headings.Add(new TocHeading("Introduction", 2, false, 1));
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
var outputStream = new MemoryStream();
options.AddOutput(new StreamData(outputStream));
options.CloseOutputStreams = false;
PdfManager.AddTableOfContents(options);

TOC の見出しをカスタマイズして追加する例です。

var heading = new TocHeading();
heading.Text = "Intro";
heading.PageNumber = 5;
heading.GenerateNumbering = true;
heading.Level = 2;
var tocOptions = new TocOptions();
tocOptions.Headings.Add(heading);
tocOptions.AddInput(new FileData("path_to_your_pdf_file.pdf"));
tocOptions.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.AddTableOfContents(tocOptions);

例外

Compress(CompressOptions)

PDF 文書を圧縮します。サイズ縮小を試みます。

public static ResultContainer Compress(CompressOptions options)

パラメータ

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

戻り値

ResultContainer: 操作結果を含むオブジェクト。

使用例

var options = new CompressOptions();
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.Compress(options);

例外

CreatePdfByChatGptRequestAsync(ChatGptRequestOptions)

ChatGPT の返信から PDF 文書を作成します。
ChatGPT に直接リクエストを送信するか、PDF ファイルをソースとして追加し、返信を出力先に保存します。

public static Task<ResultContainer> CreatePdfByChatGptRequestAsync(ChatGptRequestOptions options)

パラメータ

戻り値

Task<ResultContainer> – 操作結果を含むオブジェクト。

使用例

メッセージをリクエストに追加して ChatGPT を使用する例です。

var options = new ChatGptRequestOptions();
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
options.ApiKey = "Your API key.";
options.MaxTokens = 1000;

options.Messages.Add(new Message { Content = "You are a helpful assistant.", Role = Role.System });
options.Messages.Add(new Message { Content = "What is the biggest pizza diameter ever made?", Role = Role.User });

var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);

var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion;

1 つのメッセージだけをリクエストに追加して使用する例です。

var options = new ChatGptRequestOptions();
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
options.ApiKey = "Your API key.";
options.MaxTokens = 1000;

options.Query = "What is the lowest temperature recorded on the Earth?";

var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);

var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion;

ファイルをメッセージソースとして追加して Chat を使用する例です。

var options = new ChatGptRequestOptions();
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
options.AddInput(new FileData("TextSource.pdf"));
options.ApiKey = "Your API key.";
options.MaxTokens = 1000;
options.Query = "How many letters in the provided text?";

var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);

var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion;

例外

Merge(MergeOptions)

PDF 文書を結合します。

public static ResultContainer Merge(MergeOptions options)

パラメータ

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

戻り値

ResultContainer: 操作結果を含むオブジェクト。

使用例

var options = new MergeOptions();
options.AddInput(new FileData("path_to_your_pdf_file_1.pdf"));
options.AddInput(new FileData("path_to_your_pdf_file_2.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.Merge(options);

例外

Optimize(OptimizeOptions)

PDF 文書を最適化します。
ドキュメントを線形化し、以下を実現します。

  • 最初のページをできるだけ早く開く
  • 次のページや次ページへのリンクをできるだけ早く表示
  • ページデータが遅い回線で順次届く場合、ページを段階的に表示(最も有用なデータを先に)
  • ページ全体が受信・表示される前でも、リンククリックなどのユーザー操作を可能にする
public static ResultContainer Optimize(OptimizeOptions options)

パラメータ

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

戻り値

ResultContainer: 操作結果を含むオブジェクト。

使用例

var options = new OptimizeOptions();
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.Optimize(options);

例外

Resize(ResizeOptions)

PDF 文書のページサイズを変更します。

public static ResultContainer Resize(ResizeOptions options)

パラメータ

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

戻り値

ResultContainer: 操作結果を含むオブジェクト。

使用例

var options = new ResizeOptions();
options.PageSize = PageSize.A3;
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.Resize(options);

例外

Rotate(RotateOptions)

PDF 文書のページを回転させます。

public static ResultContainer Rotate(RotateOptions options)

パラメータ

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

戻り値

ResultContainer: 操作結果を含むオブジェクト。

使用例

var options = new RotateOptions();
options.Rotation = Rotation.On90;
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.Rotate(options);

例外

Split(SplitOptions)

PDF 文書をページ単位で分割します。

public static ResultContainer Split(SplitOptions options)

パラメータ

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

戻り値

ResultContainer: 操作結果を含むオブジェクト。

使用例

PDF ストリームを個別のページに分割し、ファイルとして保存する例です。

var options = new SplitOptions();
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file_1.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file_2.pdf"));
PdfManager.Split(options);

この例は PDF ストリームを個別のページに分割し、ストリームとして保存する方法を示しています。

using var inputStream = File.OpenRead("path_to_your_pdf_file.pdf");
using var outputStream1 = new MemoryStream();
using var outputStream2 = new MemoryStream();

var options = new SplitOptions();
options.AddInput(inputStream);
options.AddOutput(outputStream1);
options.AddOutput(outputStream2);
options.CloseOutputStreams = false;
PdfManager.Split(options);

例外

Namespace: Documentize
Assembly: Documentize.dll

 日本語