LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Convert P8 Annotation Strings to LEADTOOLS' AnnObjects
#1
Posted
:
Monday, August 27, 2018 4:38:33 PM(UTC)
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:
https://www.leadtools.com/help/leadtools/v20/dh/to/filenet-p8-and-daeja-annotations-support.htmlThe 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:
Code:
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:
Code:
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:
https://www.leadtools.com/support/forum/posts/t12578-HOW-TO--Convert-LEADTOOLS--AnnObjects-to-P8-Annotation-StringsEdited 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.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Convert P8 Annotation Strings to LEADTOOLS' AnnObjects
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.