在从缓存加载子文档时由工厂调用。
公共事件EventHandler <ResolveDocumentEventArgs> LoadDocumentFromCache
公共事件LoadDocumentFromCache作为事件(ResolveDocumentEventArgs)
公共:
事件EventHandler <ResolveDocumentEventArgs^ > ^ LoadDocumentFromCache
期间调用loaddocumentfromache事件LoadFromCache (LoadFromCacheOptions)如果正在加载的文档包含子文档。该事件为每个子文档触发一次,并允许应用程序自定义此行为。
参数 | 类型 | 描述 |
---|---|---|
发送方 | 对象 | 事件的来源 |
e | ResolveDocumentEventArgs | 事件数据 |
ResolveDocumentEventArgs包含以下成员:
输入:正在加载的源(所有者)文档。
Input:加载此子文档时使用的选项。处理程序可以修改此成员的属性(例如,replaceLoadFromCacheOptions。缓存使用不同的缓存)。
输出:加载的子文档。如果处理程序将此值保留为零,则工厂将尝试使用中设置的选项加载文档LoadFromCacheOptions.
这个示例将从子文档创建一个文档,将其保存到缓存中,然后重新加载它。它将使用LoadDocumentFromCache事件手动加载子文档。
使用Leadtools;
使用Leadtools.Codecs;
使用Leadtools.Document.Writer;
使用Leadtools.Document;
使用Leadtools.Caching;
使用Leadtools.Annotations.Engine;
使用Leadtools.Ocr;
使用Leadtools.Barcode;
使用Leadtools.Document.Converter;
公共无效LoadDocumentFromCache ()
{
//我们正在使用的缓存
FileCache cache =新FileCache ();
缓存。PolicySerializationMode = CacheSerializationMode.Json;
缓存。DataSerializationMode = CacheSerializationMode.Json;
缓存。缓存Directory =@“c: \ cache-dir”;
//要使用的文档id
常量字符串virtualDocumentId =“虚拟”;
常量字符串childDocumentId1 =“child1”;
常量字符串childDocumentId2 =“child2”;
//创建一个新文档
varcreateDocumentOptions =新CreateDocumentOptions ();
createDocumentOptions。Cache = Cache;
createDocumentOptions。文档Id = virtualDocumentId;
使用(LEADDocument document = DocumentFactory.Create(createDocumentOptions))
{
文档。Name =“虚拟”;
调试。作为sert(virtualDocumentId == document.DocumentId);
//应该有0页和文档
Debug.Assert (document.Pages。Count == 0);
Debug.Assert (document.Documents。Count == 0);
//从PDF文件中添加第1页和第2页
varloadDocumentOptions =新LoadDocumentOptions ();
loadDocumentOptions。Cache = Cache;
loadDocumentOptions。文档Id = childDocumentId1;
LEADDocument childDocument = DocumentFactory。LoadFromFile (@“C: \ LEADTOOLS21 \资源\ \ leadtools.pdf图像”, loadDocumentOptions);
//设置名称
childDocument。Name =“Child1”;
childDocument.SaveToCache ();
//现在添加页面
document.Pages.Add (childDocument.Pages [0]);
document.Pages.Add (childDocument.Pages [1]);
//添加一个空页面
DocumentPage DocumentPage = document.Pages.CreatePage(leadsize . create (LEADDocument. create)UnitsPerInch * 8.5, LEADDocument。UnitsPerInch * 11), 300);
document.Pages.Add (documentPage);
//从TIF文件中添加第3页和第4页
loadDocumentOptions =新LoadDocumentOptions ();
loadDocumentOptions。Cache = Cache;
loadDocumentOptions。文档Id = childDocumentId2;
childDocument = DocumentFactory。LoadFromFile (@“C: \ LEADTOOLS21 \资源\图片\ ocr1气管无名动脉瘘管的- 4.”, loadDocumentOptions);
//设置名称
childDocument。Name =“Child2”;
//也将它保存到缓存中
childDocument.SaveToCache ();
//现在添加页面
document.Pages.Add (childDocument.Pages [2]);
document.Pages.Add (childDocument.Pages [3]);
// 5页,2份文件(PDF和TIF)
Debug.Assert (document.Pages。Count == 5);
Debug.Assert (document.Documents。Count == 2);
//当父文档被处理时,告诉父文档处理所有子文档
文档。AutoDisposeDocuments =真正的;
//现在保存,父文档到缓存中
document.SaveToCache ();
//并告诉所有文档不要从缓存中删除自己
文档。AutoDeleteFromCache =假;
}
//钩子到DocumentFactoryLoadDocumentFromCache事件to log the documents being loaded
EventHandler
loadDocumentFromCacheHandler = (sender, e) => {
控制台。WriteLine ("从缓存加载子文档:");
控制台。WriteLine ($" Source documententid:{e.s ourcedocument . documententid}");
控制台。WriteLine ($"加载的documententid {e. loadfromcacheoptions . documententid}");
//源文档必须是虚拟的virtualDocumentId
调试。作为sert(virtualDocumentId == e.SourceDocument.DocumentId);
//正在加载的子文档为childDocumentId1或childDocumentId2
调试。作为sert(childDocumentId1 == e.LoadFromCacheOptions.DocumentId || childDocumentId2 == e.LoadFromCacheOptions.DocumentId);
//如果这是childDocumentId2,我们将自己加载它,并更改它的名称以表明它已被我们加载
如果(childdocumententid2 == e. loadfromcacheoptions . documententid)
{
//如果需要修改e.LoadFromCacheOptions,或者创建一个新实例并使用它
e.Document = DocumentFactory.LoadFromCache(e.LoadFromCacheOptions);
e.Document.Name =“LoadedByEvent”;
}
//否则,让工厂正常加载
};
DocumentFactory。loaddocumentfromcache++ = loadDocumentFromCacheHandler;
//现在,从缓存中加载文档
varloadFromCacheOptions =新LoadFromCacheOptions ();
loadFromCacheOptions。Cache = Cache;
loadFromCacheOptions。文档Id = virtualDocumentId;
使用(LEADDocument document = DocumentFactory.LoadFromCache(loadFromCacheOptions))
{
控制台。WriteLine ($"加载的虚拟文档id{文档。DocumentId}名称:{文档。名称}”);
Debug.Assert(文档。名字= =“虚拟”);
// 5页,2份文件(PDF和TIF)
Debug.Assert (document.Pages。Count == 5);
Debug.Assert (document.Documents。Count == 2);
//显示子文档名称,它应该是Child1,然后是LoadedByEvent
LEADDocument childDocument = document.Documents[0];
控制台。WriteLine ($"第一个子文档id{childDocument。DocumentId}名称:{childDocument。名称}”);
Debug.Assert (childDocument。名字= =“Child1”);
childDocument = document.Documents[1];
控制台。WriteLine ($"第二个子文档id{childDocument。DocumentId}名称:{childDocument。名称}”);
Debug.Assert (childDocument。名字= =“LoadedByEvent”);
}
DocumentFactory。loadDocumentFromCacheHandler -= loadDocumentFromCacheHandler;
//完成,删除缓存中的所有文档
保龄球isDeleted = DocumentFactory。DeleteFromCache (新LoadFromCacheOptions {Cache = Cache, DocumentId = childDocumentId1});
Debug.Assert (isDeleted);
isDeleted = DocumentFactory。DeleteFromCache (新LoadFromCacheOptions {Cache = Cache, documententid = childdocumententid2});
Debug.Assert (isDeleted);
isDeleted = DocumentFactory。DeleteFromCache (新LoadFromCacheOptions {Cache = Cache, documententid = virtualdocumententid});
Debug.Assert (isDeleted);
}
进口Leadtools
进口Leadtools。编解码器
进口Leadtools.Document.Writer
进口Leadtools.Svg
进口Leadtools。文档
进口Leadtools。缓存
进口Leadtools.Annotations.Engine
进口Leadtools。条形码
进口Leadtools。光学字符识别
进口LeadtoolsDocumentExamples.LeadtoolsExamples.Common
进口Leadtools.Document.Converter
公共子LoadDocumentFromCacheTest ()
“我们正在使用的缓存
昏暗的缓存作为新FileCache ()
缓存。PolicySerializationMode = cachesserializationmode。Json
缓存。DataSerializationMode = cacheserialize mode。Json
缓存。缓存Directory =“c: \ cache-dir”
要使用的文档id
常量virtualDocumentId作为字符串=“虚拟”
常量childDocumentId1作为字符串=“child1”
常量childDocumentId2作为字符串=“child2”
创建一个新文档
昏暗的createDocumentOptions作为新CreateDocumentOptions ()
createDocumentOptions。Cache = Cache
createDocumentOptions。文档Id = virtualDocumentId
使用文档作为LEADDocument = DocumentFactory.Create(createDocumentOptions)
文档。Name =“虚拟”
调试。作为sert(virtualDocumentId = document.DocumentId)
应该有0页和文件
Debug.Assert (document.Pages。数= 0)
Debug.Assert (document.Documents。数= 0)
从PDF文件中添加第1页和第2页
昏暗的loadDocumentOptions作为新LoadDocumentOptions ()
loadDocumentOptions。Cache = Cache
loadDocumentOptions。文档Id = childDocumentId1
昏暗的childDocument作为LEADDocument = DocumentFactory。LoadFromFile (“C: \ LEADTOOLS21 \资源\ \ leadtools.pdf图像”loadDocumentOptions)
设置名字
childDocument。Name =“Child1”
childDocument.SaveToCache ()
“现在添加页面
document.Pages.Add (childDocument.Pages (0))
document.Pages.Add (childDocument.Pages (1))
添加一个空白页面
昏暗的documentPage作为DocumentPage = document.Pages.CreatePage(leadsize . create (LEADDocument。UnitsPerInch * 8.5, LEADDocument。* 1), 300)
document.Pages.Add (documentPage)
从TIF文件中添加第3页和第4页
loadDocumentOptions =新LoadDocumentOptions ()
loadDocumentOptions。Cache = Cache
loadDocumentOptions。文档Id = childDocumentId2
childDocument = DocumentFactory。LoadFromFile (“C: \ LEADTOOLS21 \资源\图片\ ocr1气管无名动脉瘘管的- 4.”loadDocumentOptions)
设置名字
childDocument。Name =“Child2”
’同时将它保存到缓存中
childDocument.SaveToCache ()
“现在添加页面
document.Pages.Add (childDocument.Pages (2))
document.Pages.Add (childDocument.Pages (3))
’应该有5页和2个文档(PDF和TIF)
Debug.Assert (document.Pages。数= 5)
Debug.Assert (document.Documents。数= 2)
'告诉父文档在父文档被销毁时销毁所有子文档
文档。AutoDisposeDocuments =真正的
'现在保存,父文档到缓存
document.SaveToCache ()
“并告诉所有文档不要从缓存中删除自己
文档。AutoDeleteFromCache =假
结束使用
'挂钩到DocumentFactory。LoadDocumentFromCache事件to log the documents being loaded
昏暗的loadDocumentFromCacheHandler作为EventHandler(ResolveDocumentEventArgs) =
子(发送方作为对象e作为ResolveDocumentEventArgs)
控制台。WriteLine ("从缓存加载子文档:")
控制台。WriteLine ($" Source documententid:{e.s ourcedocument . documententid}")
控制台。WriteLine ($"加载的documententid {e. loadfromcacheoptions . documententid}")
源文档必须是虚拟的virtualDocumentId
调试。作为sert(virtualDocumentId = e.SourceDocument.DocumentId)
正在加载的子文档是childDocumentId1或childdocumententid2
调试。作为sert(childDocumentId1 = e.LoadFromCacheOptions.DocumentIdOrElsechilddocumententid2 = e.d ofromcacheoptions . documententid)
如果这是childDocumentId2,我们将自己加载它,并更改它的名称,以表明它已被我们加载
如果childDocumentId2 = e. loadfromcacheoptions . documententid然后
'修改e.LoadFromCacheOptions如果需要,或创建一个新实例并使用它
e.Document = DocumentFactory.LoadFromCache(e.LoadFromCacheOptions)
e.Document.Name =“LoadedByEvent”
结束如果
’否则,让工厂正常装车
结束子
AddHandlerDocumentFactory。LoadDocumentFromCache, loadDocumentFromCacheHandler
’现在,从缓存中加载文档
昏暗的loadFromCacheOptions作为新LoadFromCacheOptions ()
loadFromCacheOptions。Cache = Cache
loadFromCacheOptions。文档Id = virtualDocumentId
使用文档作为LEADDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions)
控制台。WriteLine ($"加载的虚拟文档id{文档。DocumentId}名称:{文档。名称}”)
Debug.Assert(文档。Name =“虚拟”)
’应该有5页和2个文档(PDF和TIF)
Debug.Assert (document.Pages。数= 5)
Debug.Assert (document.Documents。数= 2)
’显示子文档名称,它应该是Child1,然后是LoadedByEvent
昏暗的childDocument作为LEADDocument = document.Documents(0)
控制台。WriteLine ($"第一个子文档id{childDocument。DocumentId}名称:{childDocument。名称}”)
Debug.Assert (childDocument。Name =“Child1”)
childDocument = document.Documents(1)
控制台。WriteLine ($"第二个子文档id{childDocument。DocumentId}名称:{childDocument。名称}”)
Debug.Assert (childDocument。Name =“LoadedByEvent”)
结束使用
RemoveHandlerDocumentFactory。LoadDocumentFromCache, loadDocumentFromCacheHandler
完成,删除缓存中的所有文档
昏暗的isDeleted作为布尔= DocumentFactory。DeleteFromCache (新LoadFromCacheOptions与{.Cache = Cache, . documententid = childdocumententid1})
Debug.Assert (isDeleted)
isDeleted = DocumentFactory。DeleteFromCache (新LoadFromCacheOptions与{.Cache = Cache, . documententid = childdocumententid2})
Debug.Assert (isDeleted)
isDeleted = DocumentFactory。DeleteFromCache (新LoadFromCacheOptions与{.Cache = Cache, . documententid = virtualdocumententid})
Debug.Assert (isDeleted)
结束子
帮助收藏
光栅net|C API|c++类库|HTML5 JavaScript
文档net|C API|c++类库|HTML5 JavaScript
医疗net|C API|c++类库|HTML5 JavaScript
医疗网络查看器net
188宝金博怎么下载
支持的平台上
.NET、Java、Android和iOS/macOS程序集
C API/ c++类库
HTML5 JavaScript库
您的邮件已发送给技术支持!应该有人联系!如果你的事情很紧急,请回来聊天。
聊天时间:
周一至周五,美国东部时间上午8:30至下午6:00
感谢您的反馈!
请再次填写表格,开始新的聊天。
所有代理目前都离线。
聊天时间:
星期一至星期五
美国东部时间上午8:30 -下午6点
如需与我们联系,请填写此表格,我们将通过电子邮件与您联系。