public ActionResult <Response> CreateSampleBookmarks([FromBody] Request request) { try { using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit()) { //Set page dimensions toolkit.OutputPageHeight = 792.0f; toolkit.OutputPageWidth = 612.0f; //Create new file int result = toolkit.OpenOutputFile(FileName: $"{serverDirectory}SampleBookmarks.pdf"); if (result != 0) { throw new Exception($"Could not create destination file: SampleBookmarks.pdf"); } // Open Source File result = toolkit.OpenInputFile($"{ serverDirectory}{request.filename}.pdf"); if (result != 0) { throw new Exception($"Could not Open file: {request.filename}"); } // Add new page to output toolkit.NewPage(); toolkit.SetFont(FontName: "Arial", FontSize: 20); toolkit.PrintText(X: 72.0f, Y: 720.0f, Text: "Table of Contents"); toolkit.AddInternalLink(1, 72, 720, 72, 720, 5, 72, 720, 4); //toolkit.AddInternalLinkBookmark("Section 1", 2, 0, 0); APToolkitNET.BookmarkManager bookmarkManager = toolkit.GetBookmarkManager(); bookmarkManager.CopyBookmarks = true; APToolkitNET.Bookmark root = bookmarkManager.MakeRoot("Table of Contents", "red", APToolkitNET.FontStyle.Bold); var section1 = bookmarkManager.AddChild(root, "Section 1"); section1.SetInternalLink(1, 0, 0); var section11 = bookmarkManager.AddChild(section1, "Section 1.1"); section11.SetInternalLink(2, 0, 0); var section111 = bookmarkManager.AddChild(section1, "Section 1.1.1"); section11.SetInternalLink(3, 0, 0); var section2 = bookmarkManager.AddChild(root, "Section 2"); section2.SetInternalLink(4, 0, 0); var section21 = bookmarkManager.AddChild(section2, "Section 2.1"); section21.SetInternalLink(5, 0, 0); var section211 = bookmarkManager.AddChild(section2, "Section 2.1.1"); section211.SetInternalLink(6, 0, 0); // Close the new file to complete PDF creation toolkit.CopyForm(0, 0); toolkit.CloseInputFile(); toolkit.CloseOutputFile(); return(new Response() { FileContent = string.Empty, FileName = "SampleBookmarks.pdf", Message = "File SampleBookmarks.pdf created successfully", Success = true }); } } catch (Exception ex) { return(new Response() { FileContent = string.Empty, FileName = "", Message = "Could not Create Sample Bookmarks " + ex.Message, Success = false }); } }