LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Convert P8 Annotation Strings to PDF Annotations
#1
Posted
:
Monday, September 10, 2018 3:11:00 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 P8 annotation strings to PDF annotations using LEADTOOLS' AnnObjects as the step between:
Code:
string p8Directory = @"Some folder path";
string pdfFile = @"Some file path";
AnnContainer[] containers = P8DirectoryToLEAD(p8Directory);
LEADToPDF(containers, pdfFile);
Additional Information:P8 Annotation Strings to LEADTOOLS' AnnObjects:Original Post:
https://www.leadtools.com/support/forum/posts/t12577-HOW-TO--Convert-P8-Annotation-Strings-to-LEADTOOLS--AnnObjectsCode:
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();
}
LEADTOOLS' AnnObjects to PDF Annotations:Original Post:
https://www.leadtools.com/support/forum/posts/t12595-HOW-TO--Convert-LEADTOOLS--AnnObjects-to-PDF-AnnotationsCode:
static void LEADToPDF(IEnumerable<AnnContainer> containers, string pdfFile)
{
// Load the information about the PDF file
PDFFile file = new PDFFile(pdfFile);
file.Load();
// Convert all annotations
List<PDFAnnotation> fileAnnotations = new List<PDFAnnotation>();
int page = 1;
foreach (AnnContainer container in containers)
{
// Convert the page annotations
List<PDFAnnotation> pageAnnotations = new List<PDFAnnotation>();
AnnPDFConvertor.ConvertToPDF(container, pageAnnotations, file.Pages[page - 1].Height);
// Set the page number
foreach (PDFAnnotation annotation in pageAnnotations)
annotation.PageNumber = page;
// Add to the total list
fileAnnotations.AddRange(pageAnnotations);
// Increment the page count
page++;
}
// Write the annotations to the file
file.WriteAnnotations(fileAnnotations, pdfFile);
}
Remark: For PDF to P8 conversion, refer to the following forum post:
https://www.leadtools.com/support/forum/posts/t12587-HOW-TO--Convert-PDF-Annotations-to-P8-Annotation-StringsEdited by user Friday, September 14, 2018 10:46:44 AM(UTC)
| Reason: Updated LEAD to PDF link to new thread
Anthony Northrup
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Convert P8 Annotation Strings to PDF Annotations
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.