Last active
March 21, 2023 23:00
-
-
Save blog-aspose-cloud/0a4d9c87452096222e40955cfe8dc42f to your computer and use it in GitHub Desktop.
Redact PDF using Aspose.PDF Cloud SDK for Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This Gist contains code snippets to expunge data from PDF file using RedactAnnotation using Aspose.PDF Cloud SDK for Python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def redactPDF(): | |
try: | |
#Client credentials | |
client_secret = "1c9379bb7d701c26cc87e741a29987bb" | |
client_id = "bbf94a2c-6d7e-4020-b4d2-b9809741374e" | |
#initialize PdfApi client instance using client credetials | |
pdf_api_client = asposepdfcloud.api_client.ApiClient(client_secret, client_id) | |
# create PdfApi instance while passing PdfApiClient as argument | |
pdf_api = PdfApi(pdf_api_client) | |
# input PDF file | |
input_file = 'marketing.pdf' | |
# create an instance of RedactAnnotation class | |
redactAnnotation = asposepdfcloud.models.RedactionAnnotation() | |
redactAnnotation.contents = 'Confidential' | |
# set the color details for Annotation object | |
redactAnnotation.color = asposepdfcloud.Color(a = 0, r = 66, g = 111, b = 245) | |
# set the modify date for Annotation | |
redactAnnotation.modified = '01/01/2018 12:00:00.000 AM' | |
redactAnnotation.id = 1 | |
# set annotation flag as default | |
redactAnnotation.flags = [asposepdfcloud.models.AnnotationFlags.DEFAULT] | |
redactAnnotation.name = 'redactName' | |
# specify the rectangular region for Annotation over page | |
redactAnnotation.rect = asposepdfcloud.models.Rectangle(llx = 20, lly = 700, urx = 220, ury = 650 ) | |
redactAnnotation.page_index = 1 | |
# ZIndex factor for annotation | |
redactAnnotation.z_index = 1 | |
# set vertical and horizontal alignment as Center | |
redactAnnotation.horizontal_alignment = asposepdfcloud.models.HorizontalAlignment.CENTER | |
redactAnnotation.vertical_alignment = asposepdfcloud.models.HorizontalAlignment.CENTER | |
# point details for redaction annotation | |
redactAnnotation.quad_point = [ | |
asposepdfcloud.models.Point(5, 40), | |
asposepdfcloud.models.Point(10, 60) | |
] | |
# Annotation fill color details | |
redactAnnotation.fill_color = asposepdfcloud.Color(a = 10, r = 50, g = 168, b = 182) | |
# Overlay text to be printed on redaction annotation | |
redactAnnotation.overlay_text = 'Confidential Data' | |
# repeat the annotation occurance | |
redactAnnotation.repeat = True | |
# set the text alignment information as Left aligned | |
redactAnnotation.text_alignment = asposepdfcloud.models.HorizontalAlignment.LEFT | |
# call the API to add redaction annotation to first page of document | |
response = pdf_api.post_page_redaction_annotations(name = input_file, page_number= 1, annotations= [redactAnnotation]) | |
# print response code in console | |
print(response) | |
# print message in console (optional) | |
print('Redaction Annotation successfully added to PDF document !') | |
except ApiException as e: | |
print("Exception while calling PdfApi: {0}".format(e)) | |
print("Code:" + str(e.code)) | |
print("Message:" + e.message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment