C# Code Sample to Replace Multiple Texts inside PDF File Using Cloud API


/ Published in: C#
Save to your folder(s)

The following code sample shows how developers can replace multiple texts in a single API call in a PDF file using Aspose.Pdf for Cloud API in their applications. Developers can use Aspose REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.


Copy this code and paste it in your HTML
  1. AsposeApp.AppSID = "77***********************************";
  2. AsposeApp.AppKey = "9a*******************************";
  3.  
  4. //build URI
  5. stringstrURI = "http://api.aspose.com/v1.1/pdf/test.pdf/replaceTextList";
  6.  
  7. //sign URI
  8. stringsignedURI = Utils.Sign(strURI);
  9.  
  10. //build JSON to post
  11. TextReplace textReplace1 = new TextReplace();
  12. textReplace1.OldValue = "[!firm!]";
  13. textReplace1.NewValue = "Aspose";
  14. textReplace1.Regex = "false";
  15.  
  16. //build JSON to post
  17. TextReplace textReplace2 = new TextReplace();
  18. textReplace2.OldValue = "[!client!]";
  19. textReplace2.NewValue = "Mark";
  20. textReplace2.Regex = "false";
  21.  
  22. MultipleTextReplacestextReplaces = new MultipleTextReplaces();
  23. textReplaces.TextReplaces = new TextReplace[] { textReplace1, textReplace2 };
  24. stringstrJSON = JsonConvert.SerializeObject(textReplaces);
  25. Console.Write(strJSON);
  26. Utils.ProcessCommand(signedURI, "POST", strJSON);
  27.  
  28. //build URI
  29. strURI = "http://api.aspose.com/v1.1/storage/file/test.pdf";
  30.  
  31. //sign URI
  32. signedURI = Utils.Sign(strURI);
  33.  
  34. Stream responseStream = Utils.ProcessCommand(signedURI, "GET");
  35. using (Stream fileStream = System.IO.File.OpenWrite(@"test.pdf"))
  36. {
  37. Utils.CopyStream(responseStream, fileStream);
  38. }
  39. responseStream.Close();
  40.  
  41. //Following are required classes
  42. public class MultipleTextReplaces
  43. {
  44. publicTextReplace[] TextReplaces { get; set; }
  45. }
  46. public class TextReplace
  47. {
  48. publicTextReplace() { }
  49.  
  50. public string OldValue { get; set; }
  51. public string NewValue { get; set; }
  52. public string Regex { get; set; }
  53.  
  54. }

URL: http://www.aspose.com/docs/display/pdfcloud/Replace+Multiple+Texts+in+a+PDF

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.