Return to Snippet

Revision: 66454
at May 8, 2014 15:18 by johansonkatherine


Initial Code
AsposeApp.AppSID  = "77***********************************";
AsposeApp.AppKey = "9a*******************************";

//build URI
stringstrURI = "http://api.aspose.com/v1.1/pdf/test.pdf/replaceTextList";

//sign URI
stringsignedURI = Utils.Sign(strURI);

//build JSON to post
TextReplace textReplace1 = new TextReplace();
textReplace1.OldValue = "[!firm!]";
textReplace1.NewValue = "Aspose";
textReplace1.Regex = "false";

//build JSON to post
TextReplace textReplace2 = new TextReplace();
textReplace2.OldValue = "[!client!]";
textReplace2.NewValue = "Mark";
textReplace2.Regex = "false";

MultipleTextReplacestextReplaces = new MultipleTextReplaces();
textReplaces.TextReplaces = new TextReplace[] { textReplace1, textReplace2 };
stringstrJSON = JsonConvert.SerializeObject(textReplaces);
Console.Write(strJSON);
Utils.ProcessCommand(signedURI, "POST", strJSON);

//build URI
strURI = "http://api.aspose.com/v1.1/storage/file/test.pdf";

//sign URI
signedURI = Utils.Sign(strURI);

Stream responseStream = Utils.ProcessCommand(signedURI, "GET");
using (Stream fileStream = System.IO.File.OpenWrite(@"test.pdf"))
{
Utils.CopyStream(responseStream, fileStream);
}
responseStream.Close();

//Following are required classes
public class MultipleTextReplaces
    {
publicTextReplace[] TextReplaces { get; set; }
    }
public class TextReplace
    {
publicTextReplace() { }

public string OldValue { get; set; }
public string NewValue { get; set; }
public string Regex { get; set; }

    }

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

Initial Description
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.

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

Initial Tags
php, replace, text, api, c#

Initial Language
C#