C# PDF Annotation Viewer Library
How to open, display, draw, render, delete PDF file drawing markups using c#.net in web, windows application.
Various C# Demo Codes to Draw Markup on PDF Page Using .NET PDF Library in C# Program.
ASP.NET Annotate PDF function is based on C# PDF Annotate SDK.
In this tutorial, you learn how to add more Text annotations to PDF pages programmatically using C#
- Insert text at cursor annotation
- Note to replace annotation
- Strikethrough annotation
- Underline annotation
How to add text annotation to a PDF file using C#
- A best PDF annotator control for Visual Studio .NET support to markup PDF with various annotations in C#.NET class
- A web based markup tool able to annotate PDF in browser such as chrome, firefox and safari in ASP.NET WebForm application
- Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
- Free .NET library and components to draw on PDF file in C#.NET WinForms program
- Free online C# source code to draw markup on adobe PDF file in C#.NET framework
- Able to markup PDF and scale PDF drawing in .NET without other plug-ins
- Able to add stamps to PDF document in C#.NET
- Able to remove or crop marks from PDF document
- Support to draw freehand annotations, trikethrough text, underline text, insert and replace text
Since RasterEdge XDoc.PDF SDK is based on .NET framework 2.0, users are enabled to use it in any type of a 32-bit or 64-bit .NET application, including ASP.NET web service and Windows Forms for any .NET Framework version from 2.0 to 4.5.
How to add insert text at cursor annotation to pdf document using C#
Below are the steps and sample source code to add "Insert text at cursor" annotation to a PDF page using C#.
- Create a PDFDocument object from an existing PDF file
- Get a PDFPage object from the PDFDocument object
- Create a PDFAnnotTextInsert object
- Add the PDFAnnotTextInsert object to the PDFPage object with specified page postion
- Save the modified PDF document
String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Annot_4.pdf";
// open a PDF file
PDFDocument doc = new PDFDocument(inputFilePath);
// get the 2nd page
PDFPage page = (PDFPage)doc.GetPage(1);
// create the annotation
PDFAnnotTextInsert annot = new PDFAnnotTextInsert();
annot.Position = new PointF(300F, 500F);
// add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot);
// save to a new file
doc.Save(outputFilePath);
C# add note to replace text annotation to pdf document
The C# code below are the steps to add "Replace text" annotation to a PDF page using C#
String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Annot_5.pdf";
// open a PDF file
PDFDocument doc = new PDFDocument(inputFilePath);
// get the 2nd page
PDFPage page = (PDFPage)doc.GetPage(1);
// create the annotation
PDFAnnotTextReplace annot = new PDFAnnotTextReplace();
annot.StartPoint = new PointF(100F, 200F);
annot.EndPoint = new PointF(300F, 400F);
// add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot);
// save to a new file
doc.Save(outputFilePath);
C# add strikethrough annotation to pdf document
The C# code below are the steps to add "Strikethrough" annotation to a PDF document
String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Annot_1.pdf";
// open a PDF file
PDFDocument doc = new PDFDocument(inputFilePath);
// get the 2nd page
PDFPage page = (PDFPage)doc.GetPage(1);
// create the annotation
PDFAnnotDeleteLine annot = new PDFAnnotDeleteLine();
annot.StartPoint = new PointF(100F, 200F);
annot.EndPoint = new PointF(300F, 400F);
// add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot);
// save to a new file
doc.Save(outputFilePath);
C# add underline annotation to pdf document
The C# code below are the steps to add "Underline" annotation to a PDF document
String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Annot_2.pdf";
// open a PDF file
PDFDocument doc = new PDFDocument(inputFilePath);
// get the 2nd page
PDFPage page = (PDFPage)doc.GetPage(1);
// create the annotation
PDFAnnotUnderLine annot = new PDFAnnotUnderLine();
annot.StartPoint = new PointF(100F, 200F);
annot.EndPoint = new PointF(300F, 400F);
// add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot);
// save to a new file
doc.Save(outputFilePath);
C# retrieve annotation popup note window's properties
String inputFilePath = Program.RootPath + "\\" + "Annot_1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(doc);
foreach (IPDFAnnot annot in annots)
{
if (annot is IPDFPopupAnnot)
{
Console.WriteLine("Annotation has popup window");
IPDFPopupAnnot obj = (IPDFPopupAnnot)annot;
Console.WriteLine("Is open in the begin: " + obj.Popup.IsOpen);
Console.WriteLine("Popup window boundary: " + obj.Popup.Boundary.ToString());
}
else
{
Console.WriteLine("Annotation has no popup window");
}
}
C# retrieve annotation flags
String inputFilePath = Program.RootPath + "\\" + "Annot_1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(doc);
foreach (IPDFAnnot annot in annots)
{
Console.WriteLine("Annotation Flags");
Console.WriteLine(" Invisible: " + annot.IsInvisible);
Console.WriteLine(" Hidden: " + annot.IsHidden);
Console.WriteLine(" Print: " + annot.IsPrint);
Console.WriteLine(" No Zoom: " + annot.NoZoom);
Console.WriteLine(" No Rotate: " + annot.NoRotate);
Console.WriteLine(" No View: " + annot.NoView);
Console.WriteLine(" Read Only: " + annot.IsReadOnly);
Console.WriteLine(" Locked: " + annot.IsLocked);
Console.WriteLine(" Toggle No View: " + annot.IsToggleNoView);
Console.WriteLine(" Locked Contents: " + annot.IsLockedContents);
}
C# set annotation flags
String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Annot_1.pdf";
// create the annotation
PDFAnnotDeleteLine annot = new PDFAnnotDeleteLine();
annot.StartPoint = new PointF(100F, 200F);
annot.EndPoint = new PointF(300F, 400F);
// set annotation flags
annot.IsInvisible = false;
annot.IsPrint = true;
annot.NoRotate = true;
annot.NoZoom = true;
// add annotation
PDFAnnotHandler.AddAnnotation(inputFilePath, 1, annot, outputFilePath);