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

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, September 10, 2018 3:11:00 PM(UTC)
Anthony Northrup

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--AnnObjects
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();
}

LEADTOOLS' AnnObjects to PDF Annotations:
Original Post: https://www.leadtools.com/support/forum/posts/t12595-HOW-TO--Convert-LEADTOOLS--AnnObjects-to-PDF-Annotations
Code:

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-Strings

Edited 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.

LEAD Logo
 

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.039 seconds.