XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Bookmark: Edit Bookmark
  |  
Home ›› XDoc.PDF ›› C# PDF: Edit PDF Bookmark

C#.NET PDF SDK - Edit PDF Bookmark and Outline in C#.NET


Empower Your C# Project with Rapid PDF Internal Navigation Via Bookmark and Outline in .NET Program




An advanced PDF SDK able to edit PDF bookmark in Visual C# .NET console application


Free trial library and components for navigate PDF with bookmark in C# .NET WinForms and ASP.NET program


Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint


C# demo code for editing PDF bookmarks in Visual Studio .NET class


Help to add or insert bookmark and outline into PDF file in .NET framework


Ability to remove and delete bookmark and outline from PDF document


Merge and split PDF file with bookmark


Save PDF file with bookmark open


RasterEdge XDoc.PDF SDK package provides PDF file navigation features for your C# project. On this C# tutorial, you will learn how to retrieve, edit and update PDF bookmark and outline.




C# Project DLLs for Bookmark Edit in .NET



In order to run the sample code, the following steps would be necessary.


Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




C#.NET Sample Code: Retrieve PDF Document Outline Using C#.NET



Please directly copy and paste C# demo code below to your project to retrieve PDF file outline.




// Retrieve PDF document outline.
String inputFilePath = Program.RootPath + "\\" + "2.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
REOutline outline = doc.GetOutline();
foreach (REEntry entry in outline.Entry)
{
        Console.WriteLine("Page:     " + entry.GetPageIndex());
        Console.WriteLine("Level:    " + entry.GetLevel());
        Console.WriteLine("Position: " + entry.GetLocation());
        Console.WriteLine("Text:     " + entry.GetText());
}





C#.NET Sample Code: Update PDF Document Outline Using C#.NET



Or you can also edit and update PDF document outline as below.




String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Output_Outline.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);

// Initial a new outline object.
REOutline outline = new REOutline();

// Create 1st entry: Level = 1; Location: page index 0, y = 50.
OutLine entryChapter1 = new OutLine("Chapter 1: *******", 1, 0, 50);

// Add 1st entry to outline.
outline.Entry.Add(entryChapter1);

// Create 1st entry's child entries.
// Create 1st child entry: Level = 2; Location: page index 1, y = 0.
OutLine entryChapter11 = new OutLine("###### #### #### #### ###", 2, 1, 0);

// Connect this entry to the parent entry.
entryChapter11.SetParentREEntry(entryChapter1);

// Add 1st child of 1st entry to outline.
outline.Entry.Add(entryChapter11);

// Create 2nd child entry: Level = 2; Location: page index 2, y = 0.
OutLine entryChapter12 = new OutLine("## ## ## ## ## #### ###", 2, 2, 0);

// Connect this entry to the parent entry.
entryChapter12.SetParentREEntry(entryChapter1);

// Add 2nd child of 1st entry to outline.
outline.Entry.Add(entryChapter12);

// Create 2nd entry: Level = 1; Location: page index 3, y = 100.
OutLine entryChapter2 = new OutLine("Chapter 2: ******* ****", 1, 3, 100);

// Add 2nd entry to outline.
outline.Entry.Add(entryChapter2);

// Create 3rd entry: Level = 1; Location: page index 5, y = 200.
OutLine entryChapter3 = new OutLine("Chapter 3: **** **** ***", 1, 5, 200);

// Add 3rd entry to outline.
outline.Entry.Add(entryChapter3);

// Create 3rd entry's child entries.
// Create 1st child entry: Level = 2; Location: page index 9, y = 0.
OutLine entryChapter31 = new OutLine("# #### ###", 2, 9, 0);

// Connect this entry to the parent entry.
entryChapter31.SetParentREEntry(entryChapter3);

// Add 1st child of 3rd entry to outline.
outline.Entry.Add(entryChapter31);

// Create a child entry for the 1st child entry of the 3rd entry.
// Create entry: Level = 3; Location: page index 9, y = 500.
OutLine entryChapter311 = new OutLine("???? ???? ??? ???", 3, 9, 500);

// Connect this entry to the parent entry.
entryChapter311.SetParentREEntry(entryChapter31);

// Add 1st child of 3rd entry to outline.
outline.Entry.Add(entryChapter311);

// Create 4th entry: Level = 1; Location: page index 10, y = 0.
OutLine entryChapter4 = new OutLine("Chapter 4: ******* ** ** **** ***", 1, 10, 0);

// Add 4th entry to outline.
outline.Entry.Add(entryChapter4);

// Create 5th entry: Level = 1; Location: page index 20, y = 0.
OutLine entryChapter5 = new OutLine("Chapter 5: * ** **** **** ****", 1, 20, 0);

// Add 5th entry to outline.
outline.Entry.Add(entryChapter5);

// Update the new outline.
doc.SetOutline(outline);

doc.Save(outputFilePath);