目次を追加

Documentize PDF Manager for .NET は、PDF ドキュメントの整理とナビゲーションを強化するために、目次 (TOC) を動的に生成する強力なコンポーネントです。このコンポーネントを使用すると、PDF に目次を簡単に追加でき、文書のナビゲーションと管理が容易になります。

PDF の目次を生成する方法

PDF ファイルに目次を作成するには、次の手順に従います。

  1. TocOptions のインスタンスを作成し、目次生成設定を構成します。
  2. Title プロパティでタイトルを設定します。
  3. Headings.Add メソッドで目次の見出しをデザインします。
  4. AddInput メソッドで入力 PDF ファイルを追加します。
  5. AddOutput メソッドで目次付きの出力 PDF ファイルを指定します。
  6. AddTableOfContents メソッドを呼び出して目次を生成します。
 1// Create TocOptions object to set instructions
 2var options = new TocOptions();
 3// Set the Title
 4options.Title = "My Table of Contents";
 5// Design Headings
 6options.Headings.Add(new TocHeading("Introduction", 2));
 7options.Headings.Add(new TocHeading("Chapter I", 3));
 8options.Headings.Add(new TocHeading("Chapter II", 4));
 9options.Headings.Add(new TocHeading("Chapter III", 5));
10// Add input file path
11options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
12// Set output file path
13options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
14// Perform the process
15PdfManager.AddTableOfContents(options);

PDF の目次にブックマークを生成する

ブックマーク生成には GenerateBookmarks プロパティを使用します。

 1// Create TocOptions object to set instructions
 2var options = new TocOptions();
 3// Set the Title
 4options.Title = "My Table of Contents";
 5// Generate links in bookmarks
 6options.GenerateBookmarks = true;
 7// Design Headings
 8options.Headings.Add(new TocHeading("Introduction", 2, false, 1));
 9options.Headings.Add(new TocHeading("Chapter I", 3, true, 1));
10options.Headings.Add(new TocHeading("Chapter II", 4, true, 1));
11options.Headings.Add(new TocHeading("Example A", 4, true, 2));
12options.Headings.Add(new TocHeading("Example B", 4, true, 2));
13options.Headings.Add(new TocHeading("Example C", 4, true, 2));
14options.Headings.Add(new TocHeading("Example D", 4, true, 2));
15options.Headings.Add(new TocHeading("Chapter III", 5, true, 1));
16// Add input file path
17options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
18// Set output file path
19options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
20// Perform the process
21PdfManager.AddTableOfContents(options);

結果をストリームとして取得する方法

 1// Create TocOptions object to set instructions
 2var options = new TocOptions();
 3// Set the Title
 4options.Title = "My Table of Contents";
 5// Design Headings
 6options.Headings.Add(new TocHeading("Introduction", 2, false, 1));
 7// Add input file path
 8options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
 9// Set output stream 
10var outputStream = new MemoryStream();
11options.AddOutput(new StreamData(outputStream));
12options.CloseOutputStreams = false;
13// Perform the process
14PdfManager.AddTableOfContents(options);

目次見出しのカスタマイズ

TocHeading クラスを変更することで、目次の見出しをカスタマイズできます。たとえば、GenerateNumbering を使用したり、手動で設定したりできます。PageNumber プロパティはページへのリンクに使用され、Level プロパティで階層を指定できます。

 1// Create TocOptions object to set instructions
 2var heading = new TocHeading();
 3heading.Text = "Intro";
 4heading.PageNumber = 5;
 5heading.GenerateNumbering = true;
 6heading.Level = 2;
 7var tocOptions = new TocOptions();
 8tocOptions.Headings.Add(heading);
 9// Add input and output files
10tocOptions.AddInput(new FileData("path_to_your_pdf_file.pdf"));
11tocOptions.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
12// Generate the TOC with customized options
13PdfManager.AddTableOfContents(tocOptions);

主な機能:

  • 動的目次生成: 見出しやブックマークに基づいてエントリを自動生成し、任意の PDF ファイルに目次を作成します。
  • カスタマイズ: スタイル、書式設定、階層の深さなど、目次の外観と構造を制御できます。
  • 効率的なワークフロー: 特に大規模または複雑な文書において、手動で目次を作成する時間を大幅に削減します。
 日本語