LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Convert a PDF Annotation to a LEAD Annotation
#1
Posted
:
Friday, January 5, 2018 3:48:32 PM(UTC)
Groups: Registered
Posts: 119
Was thanked: 4 time(s) in 4 post(s)
Below you will see a code snippet that will convert PDF Annotations to LEAD Annotations.
This snippet starts off by simply creating a new PDF Document and parsing the objects located within the PDF. It then looks at each page that has been loaded, creates a new annotation container and updates the mapper according the DPI values in the image. Next you will be setting the size of the new containers that were created. The image pixels will need to be converted to annotation coordinates which can be done by calling SizeToContainerCoordinates() and passing in the image size and using
ToLeadSizeD() , this converts this LeadSize to a LeadSizeD. Finally call
ConvertFromPDF. This Converts a list of PDFAnnotation objects into a list of AnnObject objects by adding it to target AnnContainer.
You will also find a demo of this in the project below. The demo is a complete multipage demo for loading a PDF with embedded annotations, modifying them, and then resaving them to the original PDF
Code:
List<AnnContainer> Containers = new List<AnnContainer>();
RasterImage image = null;
PDFDocument pdfDoc = new PDFDocument(pdfFilename);
// Parses the objects such as text items (characters), images, rectangles, annotations, form fields,
//digital signatures, hyperlinks and fonts from one or more PDF pages
pdfDoc.ParsePages(PDFParsePagesOptions.Annotations, 1, -1);
foreach (var page in pdfDoc.Pages)
{
AnnContainer newContainer = new AnnContainer();
using (RasterImage pageImage = codecs.Load(pdfFilename, pdfDoc.Pages.IndexOf(page) + 1))
{
if (image == null)
image = pageImage.Clone();
else
image.AddPage(pageImage.Clone());
//Update this mapper with the specified DPI values.
newContainer.Mapper.MapResolutions(image.XResolution, image.YResolution, image.XResolution, image.YResolution);
//Set size of container by converting the image size coordinates to annotation coordinates
newContainer.Size = newContainer.Mapper.SizeToContainerCoordinates(image.ImageSize.ToLeadSizeD());
AnnPDFConvertor.ConvertFromPDF(page.Annotations, newContainer, LeadSizeD.Create(page.Width, page.Height));
Containers.Add(newContainer)
}
}
Edited by moderator Monday, January 22, 2018 8:36:26 PM(UTC)
| Reason: Not specified
Nick Villalobos
Developer Support Engineer
LEAD Technologies, Inc.
#2
Posted
:
Thursday, September 6, 2018 11:33:22 AM(UTC)
Groups: Registered
Posts: 119
Was thanked: 4 time(s) in 4 post(s)
Update this project to use LEADTOOLS Version 20
Nick Villalobos
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Convert a PDF Annotation to a LEAD Annotation
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.