Adicionar TOC

O Documentize PDF Manager for .NET é um componente poderoso projetado para aprimorar a organização e navegação de documentos PDF gerando dinamicamente um Sumário (TOC). Este componente simplifica o processo de adição de sumários aos seus PDFs, tornando os documentos mais fáceis de navegar e gerenciar.

Como gerar um Sumário (TOC) para um PDF

Para criar um Sumário em um arquivo PDF, siga estas etapas:

  1. Crie uma instância de TocOptions para configurar as definições de geração do TOC.
  2. Defina um título usando a propriedade Title.
  3. Desenhe os cabeçalhos do TOC usando o método Headings.Add.
  4. Adicione o arquivo PDF de entrada usando o método AddInput.
  5. Especifique o arquivo PDF de saída com o TOC usando o método AddOutput.
  6. Chame o método AddTableOfContents para gerar o TOC.
 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);

Gerar marcadores (bookmarks) em um TOC para um PDF

Você pode usar a propriedade GenerateBookmarks para a geração de marcadores.

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

Como obter o resultado como Stream

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

Personalizando o cabeçalho do TOC

Você pode personalizar o cabeçalho do Sumário modificando a classe TocHeading. Por exemplo, pode usar GenerateNumbering ou fazer a numeração manualmente.
A propriedade PageNumber é usada para links nas páginas. Também é possível utilizar a propriedade 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();
 8options.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);

Principais recursos:

  • Geração dinâmica de TOC: Crie um sumário para qualquer arquivo PDF com entradas geradas automaticamente com base em cabeçalhos ou marcadores.
  • Personalização: Controle a aparência e a estrutura do TOC, incluindo estilos, formatação e níveis de profundidade.
  • Fluxo de trabalho eficiente: Minimize o tempo gasto na criação manual de sumários, especialmente em documentos grandes ou complexos.
 Português