What Is The Way To Add Watermark Text In A Docx File Using Python?
I'm manipulating a docx file using python-docx module which doesn't seem to have watermark support. What can be the possible way to add some watermark text in a docx file using pyt
Solution 1:
If you are open to trying some other package then you may use Aspose.Words Cloud SDK for Python to add text watermark in a DOC/DOCX/Open Office document. Its free trial plan provides you 150 free monthly API calls.
P.S: I'm a developer evangelist at Aspose.
# For complete examples and data files, please go to https://github.com/aspose-words-cloud/aspose-words-cloud-python# Import moduleimport os
import asposewordscloud
import asposewordscloud.models.requests
from shutil import copyfile
# Please get your Client ID and Secret from https://dashboard.aspose.cloud.
client_id='xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx'
client_secret='xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
words_api = asposewordscloud.WordsApi(client_id,client_secret)
words_api.api_client.configuration.host='https://api.aspose.cloud'
local_test_folder= 'C:/Temp'
localFile = 'Sections.docx'
outputFile= 'Watermark.docx'
requestWatermarkText = asposewordscloud.WatermarkText(text='This is the text', rotation_angle=90)
request = asposewordscloud.models.requests.InsertWatermarkTextOnlineRequest(document=open(os.path.join(local_test_folder, localFile), 'rb'), watermark_text=requestWatermarkText)
result = words_api.insert_watermark_text_online(request)
copyfile(result.document, os.path.join(local_test_folder,outputFile))
print("Result {}".format(result.document))
Post a Comment for "What Is The Way To Add Watermark Text In A Docx File Using Python?"