Types of modification (change) that can occur in a document when history tracking is enabled.
[SerializableAttribute()]
[DataContractAttribute()]
public enum DocumentHistoryModifyType
Value | Member | Description |
---|---|---|
0 | Created | The document has been created. |
1 | Decrypted | Document has been decrypted. |
2 | Pages | Pages were added, removed, or re-arranged in the document. |
3 | PageViewPerspective | Page has been rotated or flipped. |
4 | PageAnnotations | Annotations of a page have been modified. |
5 | PageMarkDeleted | Page has been marked for deletion. |
6 | PageImage | Page raster image has been modified. |
7 | PageSvgBackImage | Page SVG back image has been modified. |
8 | PageSvg | Page SVG image has been modified. |
9 | PageText | Page text has been modified. |
10 | PageLinks | Page links have been modified. |
11 | Attachments | Attachments were added, removed, or re-arranged in the document. |
12 | PageFormFields | Page Form Fields |
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);
}
}