Extra Annotations using Python
How to add Caret Annotation into existing PDF file via Python
Caret Annotation is a symbol that indicates text editing. Caret Annotation is also a markup annotation, so the Caret class derives from the Markup class and also provides functions to get or set properties of the Caret Annotation and reset the flow of the Caret Annotation appearance. Caret annotations are often used to suggest changes, additions, or changes to the text.
Steps with which we create Caret annotation:
- Load the PDF file - new Document.
- Create new CaretAnnotation and set Caret parameters (new Rectangle, title, subject, flags, color). This annotation is used to indicate the insertion of text.
- Once we are able to append annotations to the page.
The following code snippet shows how to add Caret Annotation to a PDF file:
import aspose.pdf as ap
# Open document
document = ap.Document(input_file)
caretAnnotation1 = ap.annotations.CaretAnnotation(
document.pages[1], ap.Rectangle(200, 700.664, 308.708, 740.769, True)
)
caretAnnotation1.title = "Aspose User"
caretAnnotation1.subject = "Inserted text 1"
caretAnnotation1.flags = ap.annotations.AnnotationFlags.PRINT
caretAnnotation1.color = ap.Color.blue
document.pages[1].annotations.append(caretAnnotation1)
document.save(output_file)
Get Caret Annotation
Please try using the following code snippet to Get Caret Annotation in PDF document
import aspose.pdf as ap
document = ap.Document(input_file)
caretAnnotations = [
a
for a in document.pages[1].annotations
if (a.annotation_type == ap.annotations.AnnotationType.CARET)
]
for ca in caretAnnotations:
print(ca.rect)
Delete Caret Annotation
The following code snippet shows how Delete Caret Annotation from a PDF file using Python.
import aspose.pdf as ap
# Load the PDF file
document = ap.Document(input_file)
caretAnnotations = [
a
for a in document.pages[1].annotations
if (a.annotation_type == ap.annotations.AnnotationType.CARET)
]
for ca in caretAnnotations:
document.pages[1].annotations.delete(ca)
document.save(output_file)
Redact certain page region with Redaction Annotation using Aspose.PDF for Python
Aspose.PDF for Python via .NET supports the feature to add as well as manipulate Annotations in an existing PDF file. Redaction Annotations in PDF documents serve the purpose of permanently removing or concealing confidential information from the document. The process of editing the information involves covering or shading specific content, such as text, images, or graphics, in a way that restricts its visibility and accessibility to others. This ensures that the sensitive information remains hidden and protected within the document. In order to fulfill this requirement, a class named RedactionAnnotation is provided, which can be used to redact certain page regions or it can be used to manipulate existing RedactionAnnotations and redact them (i.e. flatten annotation and remove the text under it).
import aspose.pdf as ap
document = ap.Document(input_file)
page = document.pages[1]
redactionAnnotation = ap.annotations.RedactionAnnotation(page, ap.Rectangle(270, 190, 371, 250, True))
redactionAnnotation.title = "John Smith"
redactionAnnotation.fill_color = ap.Color.light_gray
redactionAnnotation.color = ap.Color.red
redactionAnnotation.redact()
page.annotations.append(redactionAnnotation)
document.save(output_file)
Get Redaction Annotation
import aspose.pdf as ap
document = ap.Document(input_file)
redactionAnnotations = [
a
for a in document.pages[1].annotations
if (a.annotation_type == ap.annotations.AnnotationType.REDACTION)
]
for pa in redactionAnnotations:
print(pa.rect)
Delete Redaction Annotation
import aspose.pdf as ap
document = ap.Document(input_file)
redactionAnnotations = [
a
for a in document.pages[1].annotations
if (a.annotation_type == ap.annotations.AnnotationType.REDACTION)
]
for pa in redactionAnnotations:
document.pages[1].annotations.delete(pa)
document.save(output_file)