←Select platform

SetHistory Method

Summary

Updates the annotations history tracking object of this LEADDocument.

Syntax
C#
C++/CLI
Python
public void SetHistory( 
   AnnHistory value 
) 
public:  
   void SetHistory( 
      AnnHistory^ value 
   ) 
def SetHistory(self,value): 

Parameters

value

Annotation history object. Use null to reset the history and create a new baseline.

Remarks

The annotations history tracking object of this LEADDocument.

Example
C#
Java
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); 
   } 
} 
 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.net.MalformedURLException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.net.URL; 
import java.nio.file.Files; 
import java.nio.file.Paths; 
import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.List; 
import java.util.concurrent.Callable; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
import java.util.concurrent.Future; 
import java.util.regex.Pattern; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.annotations.engine.*; 
import leadtools.barcode.*; 
import leadtools.caching.*; 
import leadtools.codecs.*; 
import leadtools.document.*; 
import leadtools.document.DocumentMimeTypes.UserGetDocumentStatusHandler; 
import leadtools.document.converter.*; 
import leadtools.document.writer.*; 
import leadtools.ocr.*; 
 
 
public void documentHistoryExample() throws URISyntaxException { 
   // Setup a cache 
   FileCache cache = new FileCache(); 
   cache.setCacheDirectory("c:\\cache-dir"); 
 
   // Create a new document 
   CreateDocumentOptions createOptions = new CreateDocumentOptions(); 
   final String documentId = "virtual"; 
   createOptions.setCache(cache); 
   createOptions.setDocumentId(documentId); 
 
   LEADDocument document = DocumentFactory.create(createOptions); 
   document.setName("Virtual"); 
   // DocumentHistory reference 
   document.getHistory().setAutoUpdate(true); 
   document.setReadOnly(false); 
 
   // Show its history 
   showHistory("virtual", document); 
 
   // Ensure it has no pages 
   assertTrue(document.getPages().size() == 0); 
   assertTrue(document.getDocuments().size() == 0); 
 
   // Add some pages 
 
   // First add the first 2 pages from a PDF file 
   LoadDocumentOptions loadOptions = new LoadDocumentOptions(); 
   loadOptions.setCache(cache); 
   LEADDocument childDocument = DocumentFactory 
         .loadFromUri(new URI("https://demo.leadtools.com/images/pdf/leadtools.pdf"), loadOptions); 
   childDocument.setAutoDeleteFromCache(false); 
   childDocument.saveToCache(); 
   childDocument.getAnnotations().setHistory(childDocument.getAnnotations().getHistory()); 
   document.getPages().add(childDocument.getPages().get(0)); 
   document.getPages().add(childDocument.getPages().get(1)); 
 
   // Add an empty page 
   DocumentPage documentPage = document.getPages() 
         .createPage(LeadSizeD.create(LEADDocument.UNITS_PER_INCH * 8.5, LEADDocument.UNITS_PER_INCH * 11), 300); 
   document.getPages().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.setAutoDeleteFromCache(false); 
   childDocument.saveToCache(); 
   document.getPages().add(childDocument.getPages().get(2)); 
   document.getPages().add(childDocument.getPages().get(3)); 
 
   // Check the document 
   assertTrue(5 == document.getPages().size()); 
   assertTrue(2 == document.getDocuments().size()); 
 
   // Get each DocumentHistoryItem 
   for (DocumentHistoryItem item : document.getHistory().getItems()) { 
      document.getHistory().setItems(null); 
      System.out.println(item); 
   } 
 
   // Enumerate through DocumentHistoryModifyType 
   DocumentHistoryModifyType[] modifyType = DocumentHistoryModifyType.values(); 
   for (DocumentHistoryModifyType type : modifyType) { 
      System.out.println("Type of modification: " + type); 
   } 
 
   document.setAutoDisposeDocuments(true); 
   document.setAutoDeleteFromCache(false); 
   document.saveToCache(); 
 
   // Load it and show its history 
   LoadFromCacheOptions loadFromCacheOptions = new LoadFromCacheOptions(); 
   loadFromCacheOptions.setCache(cache); 
   loadFromCacheOptions.setDocumentId(documentId); 
   document = DocumentFactory.loadFromCache(loadFromCacheOptions); 
   showHistory("virtual pages added", document); 
 
   // Clear the history 
   document.getHistory().clear(); 
 
   // Now, load the document from the cache 
   document = DocumentFactory.loadFromCache(loadFromCacheOptions); 
 
   assertTrue(5 == document.getPages().size()); 
   assertTrue(2 == document.getDocuments().size()); 
 
   // Remove some pages 
   document.getPages().remove(0); 
   document.getPages().remove(document.getPages().size() - 1); 
   // And rotate another 
   document.getPages().get(1).rotate(90); 
 
   assertTrue(3 == document.getPages().size()); 
   assertTrue(2 == document.getDocuments().size()); 
 
   showHistory("virtual pages removed and rotated", document); 
 
   // Clean up 
   LoadFromCacheOptions deleteFromCacheOptions = new LoadFromCacheOptions(); 
   deleteFromCacheOptions.setCache(cache); 
   deleteFromCacheOptions.setDocumentId(documentId); 
   DocumentFactory.deleteFromCache(deleteFromCacheOptions); 
} 
 
private void showHistory(String message, LEADDocument document) { 
   System.out.println("History " + message); 
   List<DocumentHistoryItem> items = document.getHistory().getItems(); 
   for (DocumentHistoryItem item : items) { 
      System.out.printf("  user:%s timestamp:%s comment:%s modifyType:%s pageNumber:%s%n", 
            item.getUserId(), item.getTimestamp(), item.getComment(), item.getModifyType(), item.getPageNumber()); 
   } 
 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

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