Welcome Guest! To enable all features, please Login or Register.



Last Go to last post Unread Go to first unread post
#1 Posted : Monday, August 27, 2018 4:38:33 PM(UTC)
Anthony Northrup

Groups: Registered, Tech Support, Administrators
Posts: 199

Was thanked: 28 time(s) in 28 post(s)

The LEADTOOLS v20 SDK supports both importing from and exporting to the FileNet P8 annotation format. For detailed information about this support, refer to the following page:

The main method used for converting from P8 annotation strings to an AnnObject is the AnnCodecs.ConvertFromIBMP8 method. Here is a simplified snippet for converting a single P8 annotation to an AnnObject:

IBMP8ReadOptions readOptions = new IBMP8ReadOptions()
    // Generally you'll want to pass screen resolution, and image resolution
    Mapper = new AnnContainerMapper(96, 96, 96, 96),
    RenderingEngine = new AnnWinFormsRenderingEngine(),
AnnObject annObject = AnnCodecs.ConvertFromIBMP8(p8AnnotationString, readOptions);

One major difference between the way the LEADTOOLS SDK handles annotations, and the P8 format is page numbers. Our annotations are added to an AnnContainer, and generally this is one AnnContainer per page of the original document. P8 annotations on the other hand each have their own page number, so when converting, we'll need to read the page number for each individually before adding to an AnnContainer. This is accessible using the AnnCodecs.ReadIBMP8PropDescAttr method, passing the constant AnnCodecs.IBM_PAGENUMBER as the second parameter.

Here is a complete sample function for converting a directory of P8 annotation files to a list of AnnContainers:

static AnnContainer[] P8DirectoryToLEAD(string p8Directory)
	List<AnnContainer> containers = new List<AnnContainer>();
	AnnRenderingEngine renderingEngine = new AnnWinFormsRenderingEngine();

	foreach (string p8File in Directory.EnumerateFiles(p8Directory, "*.xml", SearchOption.TopDirectoryOnly))
		// Read the file contents
		string p8Annotation = File.ReadAllText(p8File);

		// Determine the page number
		int page = 1;
		string pagePropValue = AnnCodecs.ReadIBMP8PropDescAttr(p8Annotation, AnnCodecs.IBM_PAGENUMBER);
		if (!String.IsNullOrEmpty(pagePropValue) && Int32.TryParse(pagePropValue, out page))
			page = Math.Max(1, page);

		// Get the AnnContainer for that page
		while (containers.Count < page)
			containers.Add(new AnnContainer());
		AnnContainer container = containers[page - 1];

		// Convert to an AnnObject
		IBMP8ReadOptions readOptions = new IBMP8ReadOptions()
			Mapper = container.Mapper,
			RenderingEngine = renderingEngine
		container.Children.Add(AnnCodecs.ConvertFromIBMP8(p8Annotation, readOptions));

	return containers.ToArray();

Remark: For AnnObject to P8 conversion, refer to the following forum post:

Edited by user Monday, September 10, 2018 12:35:37 PM(UTC)  | Reason: Added link to reverse conversion

Anthony Northrup
Developer Support Engineer
LEAD Technologies, Inc.


Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.042 seconds.