Posted By

nausherwan on 05/30/14


Tagged

document cloud word watermark AsposeWords Aspose


Versions (?)

Java Sample to Add Watermark Text to a Word Document using Aspose.Words for Cloud API


 / Published in: Java
 

URL: http://www.aspose.com/docs/display/wordscloud/Add+Watermark+Text+to+a+Word+Document

This sample code allows developers to add watermark text to a Word document on the Aspose Cloud Storage. Developers can use Aspose.Words for Cloud API in any language of your choice.

  1. String appSID = "******************";
  2. String appKey = "******************";
  3. String fileName = "MyFile.docx";
  4. String rotationAngle = "45.0";
  5.  
  6. //build URI to add watermark text
  7. String strURI = "http://api.aspose.com/v1.1/words/" + fileName + "/watermark/insertText";
  8.  
  9. String signedURI = Sign(strURI, appSID, appKey);
  10.  
  11. //serialize the JSON request content
  12. WatermarkText watermark = new WatermarkText();
  13. watermark.Text = "Watermark Text Here";
  14. watermark.RotationAngle = 45.0;
  15. String strJSON = "";
  16. Gson gson = new Gson();
  17. strJSON = gson.toJson(watermark, WatermarkText.class);
  18.  
  19. InputStream responseStream = ProcessCommand(signedURI, "POST", strJSON);
  20. String strResponse = StreamToString(responseStream);
  21. //Parse the json string to JObject
  22. BaseResponse baseResponse = gson.fromJson(strResponse,BaseResponse.class);
  23. if (baseResponse.getCode().equals("200") & baseResponse.getStatus().equals("OK"))
  24. System.out.println("Watermark text has been added successfully");
  25.  
  26. //Here is the WatermarkText class
  27. public class WatermarkText
  28. {
  29. public String Text ;
  30. public double RotationAngle ;
  31. }
  32.  
  33. //Here is the BaseResponse class
  34. public class BaseResponse {
  35. public BaseResponse() { }
  36. private String Code;
  37. private String Status;
  38. public String getCode(){return Code;}
  39. public String getStatus(){return Status;}
  40. public void setCode(String temCode){ Code=temCode;}
  41. public void setStatus(String temStatus){ Status=temStatus;}
  42. }

Report this snippet  

You need to login to post a comment.