The page number associated with this change.
public int PageNumber { get; set; }
1-based page number in the document associated with this change. The default value is 0.
This value will be set to the page number associated with the change when a modification of the following types occur:
For example, when history tracking is enabled and the user calls DocumentPage.Rotate, then a new item will be added with ModifyType set to DocumentHistoryModifyType.PageViewPerspective and PageNumber set to the number of the page in the document.
The value will be 0 (not used) when the change is associated with a modification of the following types since these are for the entire document and not a specific page:
Refer to Document Toolkit History Tracking for more information.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Document.Writer;
using Leadtools.Document;
using Leadtools.Caching;
using Leadtools.Annotations.Engine;
using Leadtools.Ocr;
using Leadtools.Barcode;
using Leadtools.Document.Converter;
public void DocumentHistoryExample()
{
// Setup a cache
FileCache cache = new FileCache();
cache.CacheDirectory = @"c:\cache-dir";
// Create a new document
var createOptions = new CreateDocumentOptions();
const string documentId = "virtual";
createOptions.Cache = cache;
createOptions.DocumentId = documentId;
using (var document = DocumentFactory.Create(createOptions))
{
document.Name = "Virtual";
// DocumentHistory reference
document.History.AutoUpdate = true;
document.IsReadOnly = false;
// Show its history
ShowHistory("virtual", document);
// Ensure it has no pages
Debug.Assert(document.Pages.Count == 0);
Debug.Assert(document.Documents.Count == 0);
// Add some pages
// First add the first 2 pages from a PDF file
var loadOptions = new LoadDocumentOptions();
loadOptions.Cache = cache;
LEADDocument childDocument = DocumentFactory.LoadFromUri(new Uri("https://demo.leadtools.com/images/pdf/leadtools.pdf"), loadOptions);
childDocument.AutoDeleteFromCache = false;
childDocument.SaveToCache();
childDocument.Annotations.SetHistory(childDocument.Annotations.GetHistory());
document.Pages.Add(childDocument.Pages[0]);
document.Pages.Add(childDocument.Pages[1]);
// Add an empty page
var documentPage = document.Pages.CreatePage(LeadSizeD.Create(LEADDocument.UnitsPerInch * 8.5, LEADDocument.UnitsPerInch * 11), 300);
document.Pages.Add(documentPage);
// Add last 2 pages from a TIFF file
childDocument = DocumentFactory.LoadFromUri(new Uri("https://demo.leadtools.com/images/pdf/leadtools.pdf"), loadOptions);
childDocument.AutoDeleteFromCache = false;
childDocument.SaveToCache();
document.Pages.Add(childDocument.Pages[2]);
document.Pages.Add(childDocument.Pages[3]);
// Check the document
Debug.Assert(5 == document.Pages.Count);
Debug.Assert(2 == document.Documents.Count);
// Get each DocumentHistoryItem
foreach (DocumentHistoryItem item in document.History.GetItems())
{
document.History.SetItems(null);
Console.WriteLine(item);
}
// Enumerate through DocumentHistoryModifyType
DocumentHistoryModifyType[] modifyType = (DocumentHistoryModifyType[])Enum.GetValues(typeof(DocumentHistoryModifyType));
foreach (var type in modifyType)
{
Console.WriteLine($"Type of modification: {type}");
}
document.AutoDisposeDocuments = true;
document.AutoDeleteFromCache = false;
document.SaveToCache();
}
// Load it and show its history
var loadFromCacheOptions = new LoadFromCacheOptions();
loadFromCacheOptions.Cache = cache;
loadFromCacheOptions.DocumentId = documentId;
using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions))
{
ShowHistory("virtual pages added", document);
// Clear the history
document.History.Clear();
}
// Now, load the document from the cache
using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions))
{
Debug.Assert(5 == document.Pages.Count);
Debug.Assert(2 == document.Documents.Count);
// Remove some pages
document.Pages.RemoveAt(0);
document.Pages.RemoveAt(document.Pages.Count - 1);
// And rotate another
document.Pages[1].Rotate(90);
Debug.Assert(3 == document.Pages.Count);
Debug.Assert(2 == document.Documents.Count);
ShowHistory("virtual pages removed and rotated", document);
}
// Clean up
var deleteFromCacheOptions = new LoadFromCacheOptions();
deleteFromCacheOptions.Cache = cache;
deleteFromCacheOptions.DocumentId = documentId;
DocumentFactory.DeleteFromCache(deleteFromCacheOptions);
}
private static void ShowHistory(string message, LEADDocument document)
{
Console.WriteLine("History " + message);
var items = document.History.GetItems();
foreach (var item in items)
{
Console.WriteLine(" user:{0} timestamp:{1} comment:{2} modifyType:{3} pageNumber:{4}",
item.UserId, item.Timestamp, item.Comment, item.ModifyType, item.PageNumber);
}
}