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:48:32 PM(UTC)
Nick Villalobos

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)
    }
}


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

Edited by moderator Monday, January 22, 2018 8:36: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.

#2 Posted : Thursday, September 6, 2018 11:33:22 AM(UTC)
Nick Villalobos

Groups: Registered
Posts: 119

Was thanked: 4 time(s) in 4 post(s)

Update this project to use LEADTOOLS Version 20

File Attachment(s):
CobvertEmbeddedPdfAnnoations V20.zip (14kb) downloaded 214 time(s).
Nick Villalobos
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
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.