This module uses the DevExpress PDF Document API (PdfDocumentProcessor) to manage PDF bookmarks. You can process the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.
Select the operation type from the drop-down menu: create or remove bookmarks in the PDF document. Once you select the action, the demo processes the document and downloads the result.
Select a Document
Sample_Main.pdf
using DevExpress.Pdf;
Stream AddBookmarks(Stream documentStream) {
using var processor = new PdfDocumentProcessor();
processor.LoadDocument(documentStream);
foreach (var page in processor.DocumentFacade.Pages) {
var destination = page.CreateFitBBoxDestination();
var bookmark = new PdfBookmark() { Destination = destination, Title = $"Page {destination.PageIndex + 1}" };
processor.Document.Bookmarks.Add(bookmark);
}
var outputStream = new MemoryStream();
processor.SaveDocument(outputStream);
outputStream.Position = 0;
return outputStream;
}
Stream DeleteBookmarks(Stream documentStream) {
using var processor = new PdfDocumentProcessor();
processor.LoadDocument(documentStream);
processor.Document.Bookmarks.Clear();
var outputStream = new MemoryStream();
processor.SaveDocument(outputStream);
outputStream.Position = 0;
return outputStream;
}