Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This Gist contains code snippets related to inserting Image and Text watermarks in Word documents using Aspose.Words Cloud SDK for Python
This Gist contains code snippets related to inserting Image and Text watermarks in Word documents using Aspose.Words Cloud SDK for Python
# For more samples, please visit https://github.com/aspose-words-cloud/aspose-words-cloud-python
import asposewordscloud
import asposewordscloud.models.requests
from asposewordscloud import ApiClient, WordsApi
from asposewordscloud.rest import ApiException
def watermark():
try:
# create an instance of WordsApi
words_api = WordsApi("88d1cda8-b12c-4a80-b1ad-c85ac483c5c5","406b404b2df649611e508bbcfcd2a77f")
# Name of input word document
inputFileName = 'source.doc'
# name of resultant file
resultantFile = 'Watermarked.doc'
# name of image to be watermarked
watermarkImage = 'confidential.jpg'
# Upload source Word document to Cloud Storage
words_api.upload_file(asposewordscloud.models.requests.UploadFileRequest(open('C:\\Users\\shahbnay\\Downloads\\'+inputFileName, 'rb'), "", None))
# upload image to be watermarked
words_api.upload_file(asposewordscloud.models.requests.UploadFileRequest(open('C:\\Users\\shahbnay\\Downloads\\'+watermarkImage, 'rb'), "", None))
# Create InsertImage request while passing input Word document, rotating angel, image name and resultant file names as arguments
insert_request = asposewordscloud.models.requests.InsertWatermarkImageRequest(name=inputFileName,dest_file_name=resultantFile,rotation_angle=45,image=watermarkImage)
# inititate Image watermarking operation
words_api.insert_watermark_image(insert_request)
# print message in console (optional)
print('Watermark inserted successfully !')
except ApiException as e:
print("Exception while calling WordsApi: {0}".format(e))
# For more samples, please visit https://github.com/aspose-words-cloud/aspose-words-cloud-python
import asposewordscloud
import asposewordscloud.models.requests
from asposewordscloud import ApiClient, WordsApi
from asposewordscloud.rest import ApiException
def textWatermark():
try:
# create an instance of WordsApi
words_api = WordsApi("88d1cda8-b12c-4a80-b1ad-c85ac483c5c5","406b404b2df649611e508bbcfcd2a77f")
# Name of input word document
inputFileName = 'source.doc'
# name of resultant file
resultantFile = 'Watermarked.doc'
# Upload source Word document to Cloud Storage
words_api.upload_file(asposewordscloud.models.requests.UploadFileRequest(open('C:\\Users\\shahbnay\\Downloads\\'+inputFileName, 'rb'), "", None))
# Watermark object defining text and rotating angle
watermark_string = asposewordscloud.WatermarkText(rotation_angle = 90, text='confidential')
# create an object of InsertWatermarkTextRequest
insert_request = asposewordscloud.models.requests.InsertWatermarkTextRequest(name=inputFileName,watermark_text=watermark_string,dest_file_name=resultantFile)
# initiate the watermarking operation
words_api.insert_watermark_text(insert_request)
# print message in console (optional)
print('Watermark inserted successfully !')
except ApiException as e:
print("Exception while calling WordsApi: {0}".format(e))
# call the method to add text watermark
textWatermark()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment