LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Convert PDF Annotations to P8 Annotation Strings
#1
Posted
:
Monday, September 10, 2018 3:19:37 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 199
Was thanked: 28 time(s) in 28 post(s)
This post combines the logic from two other annotation conversion posts. The result allows you to convert PDF annotations to P8 annotation strings using LEADTOOLS' AnnObjects as the step between:
Code:
string pdfFile = @"Some file path";
string p8Directory = @"Some folder path";
AnnContainer[] containers = PDFToLEAD(pdfFile);
LEADToP8Directory(containers, p8Directory);
Additional Information:PDF Annotations to LEADTOOLS' AnnObjects:Original Post:
https://www.leadtools.com/support/forum/posts/m43645-HOW-TO--Convert-a-PDF-Annotation-to-a-LEAD-Annotation#post43645Note: I have simplified the original code slightlyCode:
static AnnContainer[] PDFToLEAD(string pdfFile)
{
List<AnnContainer> containers = new List<AnnContainer>();
using (RasterCodecs codecs = new RasterCodecs())
using (PDFDocument pdfDoc = new PDFDocument(pdfFile))
{
// Parses the annotations
pdfDoc.ParsePages(PDFParsePagesOptions.Annotations, 1, -1);
// Convert all annotations
foreach (PDFDocumentPage page in pdfDoc.Pages)
{
// Configure the page number for the container
AnnContainer container = new AnnContainer()
{
PageNumber = page.PageNumber
};
// Configure the DPI of the container
using (CodecsImageInfo info = codecs.GetInformation(pdfFile, false, page.PageNumber))
container.Mapper.MapResolutions(
container.Mapper.DeviceDpiX, container.Mapper.DeviceDpiY,
info.XResolution, info.YResolution
);
// Convert the page annotations
AnnPDFConvertor.ConvertFromPDF(
page.Annotations, container,
new LeadSizeD(page.Width, page.Height)
);
// Add to the total list
containers.Add(container);
}
}
return containers.ToArray();
}
LEADTOOLS' AnnObjects to P8 Annotation Strings:Original Post:
https://www.leadtools.com/support/forum/posts/t12578-HOW-TO--Convert-LEADTOOLS--AnnObjects-to-P8-Annotation-StringsCode:
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 PDF conversion, refer to the following forum post:
https://www.leadtools.com/support/forum/posts/t12586-HOW-TO--Convert-P8-Annotation-Strings-to-PDF-AnnotationsAnthony Northrup
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Convert PDF Annotations 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.