PDF Toolkit

Samples

Add PDF Annotations

This Code sample requires the PDF Toolkit and is found in: C:\Aquaforest\PDF Toolkit\samples\PDFAnnotations

    
using Aquaforest.PDF;
using System;
using System.Collections.Generic;
    
namespace PDFAnnotations
{
    internal class PDFAnnotations
    {
        private static void Main(string[] args)
        {
            string inputFile = @"..\documents\source\image_pdf.pdf";
            string outputFile = @"..\documents\output\pdfannotations.pdf";
            PDFRectangle rect = new PDFRectangle(10, 10, 300, 50);
            PDFAnnotation annotation = new PDFAnnotation(PDFAnnotationType.PDFAnnotationRubberStamp, rect, "PDF Tookit", PDFRubberStampImages.NotForPublicRelease);
            PDFAnnotation annotation1 = new PDFAnnotation(PDFAnnotationType.PDFAnnotationRubberStamp, rect, "PDF Tookit", PDFRubberStampImages.NotApproved);
            PDFAnnotation annotation3 = new PDFAnnotation(PDFAnnotationType.PDFAnnotationTextMarkup, rect, "PDF Tookit");
    
            PDFAnnotation annotation5 = new PDFAnnotation(PDFAnnotationType.PDFAnnotationLink, rect, "PDF Tookit");
            PDFAnnotation annotation6 = new PDFAnnotation(PDFAnnotationType.PDFAnnotationLine, rect, "PDF Tookit", PDFAnnotationLineSubtypes.SQUARE);
            Dictionary annotaions = new Dictionary();
    
            annotation5.LinkURL = "https://www.aquaforest.com/en/pdftoolkit.asp";
            annotation3.AnnotationColor = PDFColor.Yellow;
            annotaions.Add(1, annotation);
            annotaions.Add(2, annotation1);
            annotaions.Add(3, annotation3);
    
            annotaions.Add(5, annotation5);
            annotaions.Add(6, annotation6);
            AddAnotations(inputFile, outputFile, annotaions);
        }
    
        public static void AddAnotations(string file, string output, Dictionary annotaions)
        {
            try
            {
                PDFDocument pdfDoc = new PDFDocument(file);
                foreach (var key in annotaions.Keys)
                {
                    pdfDoc.GetPage(key).AddAnnotation(annotaions[key], pdfDoc);
                }
    
                pdfDoc.Save(output);
                pdfDoc.Close();
            }
            catch (Exception)
            { }
        }
    }
}