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 : Friday, January 5, 2018 3:53:32 PM(UTC)
Nick Villalobos

Groups: Registered, Manager, Tech Support, Administrators
Posts: 96

Was thanked: 2 time(s) in 2 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)
    }
}


File Attachment(s):
ConvertEmbededPDFAnn.zip (98kb) downloaded 17 time(s).

Edited by moderator Monday, January 22, 2018 8:41:26 PM(UTC)  | Reason: Not specified

Nick Villalobos
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-2018, Yet Another Forum.NET
This page was generated in 0.159 seconds.