←Select platform

DocumentHistory Class

Summary

History tracking of LEADDocument.

Syntax
C#
VB
C++
[DataContractAttribute()] 
public class DocumentHistory 
<DataContractAttribute()>  
Public Class DocumentHistory 
public: 
   [DataContractAttribute] 
   ref class DocumentHistory 
Remarks

DocumentHistory manages the history of the document. It can be accessed through the History property of LEADDocument. It contains an internal list of DocumentHistoryItem objects for each modification or change that occurred in the document.

History tracking is enabled when the value of AutoUpdate is true.

The items can be retrieved, updated or cleared through GetItems, SetItems and Clear respectively.

For more information, refer to Document Toolkit History Tracking.

Example

This example enables history tracking on a document and shows the results.

C#
VB
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"; 
		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(); 
		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); 
 
		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); 
	} 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Document.Writer 
Imports Leadtools.Svg 
Imports Leadtools.Document 
Imports Leadtools.Caching 
Imports Leadtools.Annotations.Engine 
Imports Leadtools.Barcode 
Imports Leadtools.Ocr 
Imports LeadtoolsDocumentExamples.LeadtoolsExamples.Common 
Imports Leadtools.Document.Converter 
 
Public Shared Sub DocumentHistoryExample() 
   ' Setup a cache 
   Dim cache As New FileCache() 
   cache.CacheDirectory = "c:\cache-dir" 
 
   ' Create a New document 
   Dim createOptions As New CreateDocumentOptions() 
   Const documentId As String = "virtual" 
   createOptions.Cache = cache 
   createOptions.DocumentId = documentId 
 
   Using document As LEADDocument = DocumentFactory.Create(createOptions) 
      document.Name = "Virtual" 
      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 
      Dim loadOptions As New LoadDocumentOptions() 
      loadOptions.Cache = cache 
      Dim childDocument As LEADDocument = DocumentFactory.LoadFromUri(New Uri("https://demo.leadtools.com/images/pdf/leadtools.pdf"), loadOptions) 
      childDocument.AutoDeleteFromCache = False 
      childDocument.SaveToCache() 
      document.Pages.Add(childDocument.Pages(0)) 
      document.Pages.Add(childDocument.Pages(1)) 
 
      ' Add an empty page 
      Dim documentPage As 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) 
 
      document.AutoDisposeDocuments = True 
 
      document.AutoDeleteFromCache = False 
      document.SaveToCache() 
   End Using 
 
   ' Load it And show its history 
   Dim loadFromCacheOptions As New LoadFromCacheOptions 
   loadFromCacheOptions.Cache = cache 
   loadFromCacheOptions.DocumentId = documentId 
   Using document As LEADDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions) 
      ShowHistory("virtual pages added", document) 
 
      ' Clear the history 
      document.History.Clear() 
   End Using 
 
   ' Now, load the document from the cache 
   loadFromCacheOptions = New LoadFromCacheOptions 
   loadFromCacheOptions.Cache = cache 
   loadFromCacheOptions.DocumentId = documentId 
   Using document As LEADDocument = 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) 
   End Using 
 
   ' Clean up 
   Dim deleteFromCacheOptions As New LoadFromCacheOptions 
   deleteFromCacheOptions.Cache = cache 
   deleteFromCacheOptions.DocumentId = documentId 
   DocumentFactory.DeleteFromCache(deleteFromCacheOptions) 
End Sub 
 
Private Shared Sub ShowHistory(message As String, document As LEADDocument) 
   Console.WriteLine("History " + message) 
   Dim items As List(Of DocumentHistoryItem) = document.History.GetItems() 
   For Each item As DocumentHistoryItem In items 
      Console.WriteLine("  user:{0} timestamp:{1} comment:{2} modifyType:{3} pageNumber:{4}", 
         item.UserId, item.Timestamp, item.Comment, item.ModifyType, item.PageNumber) 
   Next 
End Sub 
Requirements
Target Platforms
Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.