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:19:37 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 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#post43645
Note: I have simplified the original code slightly
Code:

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-Strings
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 PDF conversion, refer to the following forum post:
https://www.leadtools.com/support/forum/posts/t12586-HOW-TO--Convert-P8-Annotation-Strings-to-PDF-Annotations
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.050 seconds.