|
<< Click to Display Table of Contents >> Navigation: Gnostice Document Studio .NET > Going Deeper > Document Engines > Working with PDF > Enhancement > Add annotations to PDF |
In this section we present example code to add annotations to an existing PDF document. Before proceeding further please make sure that the prerequisite steps as listed in the Document Engines parent topic are followed.
Given below is the sample code.
using (var pdfDoc = new PDF())
{
// Load an existing PDF document
pdfDoc.LoadDocument(@"input.pdf");
// Add a text annotation to page 1
var textAnnot = new PDFTextAnnot(x: 0.7f, y: 2.6f, Color.Orange)
{
Title = "My Review",
Subject = "1. Date",
Content = "Please update the date",
AnnotIcon = PDFTextAnnotIcon.Comment
};
pdfDoc.AddAnnot(textAnnot, pageNo: 1);
// Add a stamp annotation to page 1
var stampAnnot = new PDFStampAnnot(new SimpleRect(3f, 0.2f, 2, 1), Color.Gold)
{
Stamp = PDFAnnotStamps.Approved,
Content = "This is approved subject to conditions.",
Title = "Approved conditionally",
Subject = "My review"
};
pdfDoc.AddAnnot(stampAnnot, pageNo: 1);
// Add a link annotation to page 1
var linkAnnot = new PDFLinkAnnot(new SimpleRect(2.2f, 1.2f, 1.2f, 0.5f));
linkAnnot.AddActionURI("http://www.gnostice.com");
pdfDoc.AddAnnot(linkAnnot);
// Add a squiggly markup annotation to page 1
var squigglyAnnot = new PDFMarkupAnnot
{
MarkupStyle = PDFTextMarkupStyle.Squiggly,
Content = "The the 'G' in 'Gnostice' silent",
Title = "My review",
Subject = "Document review",
Color = Color.Blue
};
squigglyAnnot.SetQuadPoints(new SimpleRect(1.38f, 3.35f, 0.52f, 0.1f));
pdfDoc.AddAnnot(squigglyAnnot);
// Add a highlight markup annotation to page 1
PDFMarkupAnnot sa1 = new PDFMarkupAnnot
{
MarkupStyle = PDFTextMarkupStyle.Highlight,
Content = "This is important.",
Title = "Instructions",
Subject = "For end-users",
Color = Color.Lime
};
sa1.SetQuadPoints(new SimpleRect(1f, 3f, 4.1f, 0.25f));
// Add annotation to page 1
pdfDoc.AddAnnot(sa1);
// Save the edited document to file
pdfDoc.Save(@"annotation_demo.pdf");
}