How to add Sticky Notes, Insert Text at cursor, .. Annotations in existing PDF file using iTextSharp with C#?

前端 未结 2 1891
逝去的感伤
逝去的感伤 2021-01-25 21:13

I want to add Annotations comment in existing PDF file using iTextSharp with C#.

Please give sample code to add Annotations in existing PDF file.

Here PS Script

2条回答
  •  不知归路
    2021-01-25 21:33

    The iText(Sharp) example TimetableAnnotations1.java / TimetableAnnotations1.cs from chapter 7 of iText in Action — 2nd Edition shows how to add annotations to existing PDFs in general.

    The central code is (in the C# example):

    rect = GetPosition(screening);
    annotation = PdfAnnotation.CreateText(
        stamper.Writer, rect, movie.MovieTitle,
        string.Format(INFO, movie.Year, movie.Duration),
        false, "Help"
    );
    annotation.Color = WebColors.GetRGBColor(
        "#" + movie.entry.category.color
    );
    stamper.AddAnnotation(annotation, page);
    

    where stamper is a PdfStamper working on your PDF file; movie is a data structure the example retrieves title, text and color of the annotation from.

    PdfAnnotation offers multiple other Create... methods to create other types of annotations.

提交回复
热议问题