C# Code Sample to Replace Multiple Texts in PDF





1
Date Submitted Thu. May. 8th, 2014 5:34 AM
Revision 1 of 1
Helper johansonkatherine
Tags cloud | in | inside | pdf | Replace | Text
Comments 0 comments
The following code sample shows how developers can replace multiple texts in a PDF file in C# 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.


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; }

    }


 

Katherine Johanson

Comments

There are currently no comments for this snippet.

Voting

Votes Down