LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Convert LEADTOOLS' AnnObjects to P8 Annotation Strings
#1
Posted
:
Monday, August 27, 2018 4:52:40 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 an AnnObject to a P8 annotation string is the
AnnCodecs.ConvertToIBMP8 method. Here is a simplified snippet for converting an AnnObject to a P8 annotation string:
Code:
IBMP8WriteOptions writeOptions = new IBMP8WriteOptions()
{
Formatted = true,
ForMultiPageTiff = false,
InferForMultiPageTiffFromMetadata = false,
InferPageNumberFromMetadata = false,
// Generally you'll want to pass screen resolution, and image resolution
Mapper = new AnnContainerMapper(96, 96, 96, 96),
PageNumber = 1
};
string p8AnnotationString = AnnCodecs.ConvertToIBMP8(annObject, writeOptions);
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 specify the page number for each annotation. This can be set with the
PageNumber property of the
IBMP8WriteOptions class.
Here is a complete sample function for converting a list of AnnContainers to a directory of P8 annotation files:
Code:
static void LEADToP8Directory(IEnumerable<AnnContainer> containers, string p8Directory)
{
Directory.CreateDirectory(p8Directory);
int page = 1;
foreach (AnnContainer container in containers)
{
IBMP8WriteOptions writeOptions = new IBMP8WriteOptions()
{
Formatted = true,
ForMultiPageTiff = false,
InferForMultiPageTiffFromMetadata = false,
InferPageNumberFromMetadata = false,
Mapper = container.Mapper,
PageNumber = page++
};
foreach (AnnObject annObject in container.Children)
{
// Provide a default guid
if (String.IsNullOrEmpty(annObject.Guid))
annObject.Guid = Guid.NewGuid().ToString();
File.WriteAllText(
Path.Combine(p8Directory, $"{annObject.Guid}.xml"),
AnnCodecs.ConvertToIBMP8(annObject, writeOptions)
);
}
}
}
Remark: For P8 to AnnObject conversion, refer to the following forum post:
https://www.leadtools.com/support/forum/posts/t12577-HOW-TO--Convert-P8-Annotation-Strings-to-LEADTOOLS--AnnObjectsEdited by user Monday, September 10, 2018 2:11:34 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 LEADTOOLS' AnnObjects to P8 Annotation Strings
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.