Skip to content

Instantly share code, notes, and snippets.

@aspose-cloud
Last active November 29, 2021 04:23
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-cloud/1c127119d658f01c061ac26db3b9b37c to your computer and use it in GitHub Desktop.
Save aspose-cloud/1c127119d658f01c061ac26db3b9b37c to your computer and use it in GitHub Desktop.
This Gist contains code snippets regarding the addition of Text and Image watermarks to PDF files using Aspose.PDF Cloud SDK for Python
# For more examples, please visit https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-python
def textWatermark():
try:
#Client credentials
client_secret = "406b404b2df649611e508bbcfcd2a77f"
client_id = "88d1cda8-b12c-4a80-b1ad-c85ac483c5c5"
#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 name
input_file = 'awesomeTable.pdf'
# page number of PDF where text stamp needs to be added
pageNumber = 1
textStamp = asposepdfcloud.models.Stamp
textStamp.type = 'Text'
textStamp.background = True
textStamp.horizontal_alignment = 1 #Left
textStamp.opacity = 0.5
textStamp.rotate = 1
textStamp.rotate_angle = 45
textStamp.x_indent=100
textStamp.y_indent=100
textStamp.zoom=1.5
textStamp.value = 'Confidential'
textState = asposepdfcloud.TextState
textState.font_size = 20
textState.font= 'Arial'
textState.foreground_color = {'A': 0,
'R': 200,
'G': 0,
'B': 0 }
textState.background_color = {
'A': 10,
'R': 0,
'G': 0,
'B': 0}
textState.font_style = 2
textStamp.vertical_alignment = 1
#invoke Aspose.Pdf Cloud SDK API to insert text watermark in PDF file
response = pdf_api.post_page_text_stamps(input_file, pageNumber, textStamp)
# print message in console (optional)
print('Text Watermark 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)
This Gist contains code snippets regarding the addition of Text and Image watermarks to PDF files using Aspose.PDF Cloud SDK for Python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment