Summary
Spire.Cloud.Word provides a watermarksApi interface for adding watermarks, including SetTextWatermark and SetImageWatermark, which are described in more detail in this article.
About Spire.Cloud
Spire.Cloud is a cloud-based Office document processing software that supports online creation, editing, saving and printing of Office (Word / Excel / PPT) documents. It supports many programming languages such as.NET, Java, PHP, Python, JavaScript, etc. It can operate documents in DOC, DOCX, XLS X, PPT, PPTX, PDF, etc.
You can also call the interface provided by Spire.Cloud Web API SDK to operate Word, Excel, PPT, PDF documents. This paper takes calling Spire.Cloud.Word.SDK to operate Word documents in VS programs as an example to add watermarks.
Specific steps:
Step 1: dll file acquisition and reference.Through the Nuget website download Get the Spire.Cloud.Word.SDK Package and add the DLL of Spire.Cloud.Word.Sdk.dll and its dependencies to the program (see figure below); or install it in the VS program by Nuget search, steps you can refer to Here.
Step 2: ID and Key acquisition.stay Ice Blue Cloud Web Page Register an account and log in, create an app in the My Apps section, get an App ID and an App Key.
Step 3: File path setting.In the "My Documents" section of the Ice Blue Cloud Web page, create two folders, input and output, and add the Word documents and pictures of the test under the input folder.Through the VS code program, the generated watermarked Word document is saved directly to the output folder.See below for specific code manipulation methods.
[Example 1] Add a text watermark
using Spire.Cloud.Word.Sdk; using Spire.Cloud.Word.Sdk.Api; using Spire.Cloud.Word.Sdk.Client; using Spire.Cloud.Word.Sdk.Model; using System; namespace txtwatermark { class Program { static String appId = "application program App ID"; static String appKey = "application program App Key"; static void Main(string[] args) { //Configure Account Information Configuration wordConfiguration = new Configuration(appId, appKey); //Establish TablesApi Example WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration); //Set folders, test documents, watermarks and watermarking styles, etc. string inputfolder = "input"; string storage = null; string password = null; var document = "testfile.docx"; string name = document; TextWatermark body = new TextWatermark("Watermark") { Layout = TextWatermark.LayoutEnum.Diagonal, Font = new Font(60, "Song Style") { Color = new Color(100, 100, 100) } }; //call SetTextWatermark Interface Add Text Watermark to Word Document and save to specified file path string destFilePath = "output/SetTextWatermark.docx"; watermarksApi.SetTextWatermark(name, body, inputfolder, storage, password, destFilePath); } } }
Text Watermark Add Effect:
[Example 2] Add a picture watermark
using Spire.Cloud.Word.Sdk; using Spire.Cloud.Word.Sdk.Api; using Spire.Cloud.Word.Sdk.Client; using System; namespace ImgWatermark { class Program { static String appId = "application program App ID "; static String appKey = "application program App Key "; static void Main(string[] args) { //Configure Account Information Configuration wordConfiguration = new Configuration(appId, appKey); //Establish TablesApi Example WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration); //Set folders, test documents, pictures used for watermarking, watermarking styles, etc. string inputfolder = "input"; string storage = null; int scaling = 120; bool washout = true; string password = null; var document = "testfile.docx"; string name = document; string imagePath = "input/logo.png"; //call SetImageWatermark Interface Add Picture Watermark to Word Document and save to specified file path string destFilePath = "output/SetImageWatermark.docx"; watermarksApi.SetImageWatermark(name, imagePath, inputfolder, storage, scaling, washout, password, destFilePath); } } }
Picture Watermark Add Effect:
(End of this article)