Changes Required when Migrating from Aspose.Pdf.Kit

Working with Annotations

C#

 //open document

PdfAnnotationEditor annotationEditor = new PdfAnnotationEditor();

annotationEditor.BindPdf("input.pdf");

//create annotation

FreeTextAnnotation annotation = new FreeTextAnnotation();

annotation.Modified = DateTime.Now;

annotation.Contents = "Contents...";

annotation.Subject = "Subject";

annotation.Color = Color.Green;

//modify annotation

annotationEditor.ModifyAnnotations(1, 1, annotation);

//save updated PDF file

annotationEditor.Save("output.pdf");

Working with Attachments

C#

 //open document

PdfExtractor pdfExtractor = new PdfExtractor();

pdfExtractor.BindPdf("input.pdf");

//extract attachments

pdfExtractor.ExtractAttachment();

//get attachment names

ArrayList attachmentNames = (ArrayList) pdfExtractor.GetAttachNames();

foreach (string attachmentName in attachmentNames)

Console.WriteLine("Name : {0}", attachmentName);

Working with Replace Text

C#

 //create PdfContentEditor object to edit text

PdfContentEditor editor = new PdfContentEditor();

editor.BindPdf("input.pdf");

// Create font and mark it to be embedded

Aspose.PDF.Text.Font font = FontRepository.FindFont("Courier New");

font.IsEmbedded = true;

//create textState object

TextState textState = new TextState();

textState.Font = font;

textState.FontSize = 17;

textState.FontStyle = FontStyles.Bold | FontStyles.Italic;

textState.ForegroundColor = System.Drawing.Color.Red;

//change text with specified font

editor.ReplaceText("hello world", 1, "hi world", textState);

//save document

editor.Save("output.pdf");

Form field naming