Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/31c3fc7129c753b563f05dd29e91fc5b to your computer and use it in GitHub Desktop.
Save aspose-com-gists/31c3fc7129c753b563f05dd29e91fc5b to your computer and use it in GitHub Desktop.
Working with Annotations in PDF files using C++
Examples for Working with Annotations in PDF files using C++
// Create an instance of the PdfContentEditor class
auto editor = MakeObject<Facades::PdfContentEditor>();
// Load the sample PDF file
editor->BindPdf(u"SourceDirectory\\Sample 1.pdf");
// Create annotation
editor->CreateText(System::Drawing::Rectangle(400, 700, 100, 100), u"Title", u"Welcome to Aspose", true, u"Comment", 1);
// Save PDF file
editor->Save(u"OutputDirectory\\AnnotationSample.pdf");
// Create an instance of the PdfAnnotationEditor class
System::SharedPtr<Aspose::Pdf::Facades::PdfAnnotationEditor> annotationEditor = System::MakeObject<Aspose::Pdf::Facades::PdfAnnotationEditor>();
// Load an existing PDF document
annotationEditor->BindPdf(u"SourceDirectory\\AnnotationSample.pdf");
// Delete All Annotations
annotationEditor->DeleteAnnotations();
// Save the document
annotationEditor->Save(u"OutputDirectory\\AnnotationSample_out.pdf");
// Create an instance of the PdfAnnotationEditor class
System::SharedPtr<Aspose::Pdf::Facades::PdfAnnotationEditor> annotationEditor = System::MakeObject<Aspose::Pdf::Facades::PdfAnnotationEditor>();
// Load an existing PDF document
annotationEditor->BindPdf(u"SourceDirectory\\AnnotationSample.pdf");
// Delete Text Annotations
annotationEditor->DeleteAnnotations(u"Text");
// Save the document
annotationEditor->Save(u"OutputDirectory\\AnnotationSample_out.pdf");
// Create an instance of the PdfAnnotationEditor class
System::SharedPtr<Aspose::Pdf::Facades::PdfAnnotationEditor> annotationEditor = System::MakeObject<Aspose::Pdf::Facades::PdfAnnotationEditor>();
// Load an existing PDF document
annotationEditor->BindPdf(u"SourceDirectory\\AnnotationSample.pdf");
// Delete Annotation By Name
annotationEditor->DeleteAnnotation(u"4df2cf36-d961-4d83-a39e-4b0069f97e0b");
// Save the document
annotationEditor->Save(u"OutputDirectory\\AnnotationSample_out.pdf");
// Create an instance of the sample PDF file
auto document = MakeObject <Aspose::Pdf::Document>(u"SourceDirectory\\AnnotationSample.pdf");
// Create an instance of the PdfAnnotationEditor class
System::SharedPtr<Aspose::Pdf::Facades::PdfAnnotationEditor> annotationEditor = System::MakeObject<Aspose::Pdf::Facades::PdfAnnotationEditor>();
// Load the sample PDF document
annotationEditor->BindPdf(document);
// Create an annotation object
System::SharedPtr<Aspose::Pdf::Annotations::TextAnnotation> annotation = System::MakeObject<Aspose::Pdf::Annotations::TextAnnotation>(document->get_Pages()->idx_get(1), MakeObject<Aspose::Pdf::Rectangle>(200, 400, 400, 600));
// Set modified date
annotation->set_Modified(System::DateTime::get_Now());
// Set Title
annotation->set_Title(u"NEW AUTHOR");
// Set Content
annotation->set_Contents(u"NEW CONTENTS");
// Set Subject
annotation->set_Subject(u"NEW SUBJECT");
// Set open flag
annotation->set_Open(true);
// Modify Annotation
annotationEditor->ModifyAnnotations(1, 1, annotation);
// Save the document
annotationEditor->Save(u"OutputDirectory\\AnnotationSample_out.pdf");
// Create an instance of the PdfAnnotationEditor class
System::SharedPtr<Aspose::Pdf::Facades::PdfAnnotationEditor> annotationEditor = System::MakeObject<Aspose::Pdf::Facades::PdfAnnotationEditor>();
// Load the sample PDF file
annotationEditor->BindPdf(u"SourceDirectory\\Sample 1.pdf");
// Create an array of annotation types
System::ArrayPtr<Aspose::Pdf::Annotations::AnnotationType> annotationTypes = System::MakeArray<Aspose::Pdf::Annotations::AnnotationType>({ Aspose::Pdf::Annotations::AnnotationType::Text, Aspose::Pdf::Annotations::AnnotationType::Highlight });
// Extract Annotations
System::SharedPtr<System::Collections::Generic::IList<System::SharedPtr<Aspose::Pdf::Annotations::Annotation>>> annotationList = annotationEditor->ExtractAnnotations(1, 2, annotationTypes);
// Loop through the annotations
for (System::SharedPtr<Aspose::Pdf::Annotations::Annotation> annotation : annotationList)
{
// Display annotation content
Console::WriteLine(annotation->get_Contents());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment