public static void Run() { // ExStart:1 PdfApi pdfApi = new PdfApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); string fileName = "test.pdf"; string storage = null; string folder = null; Com.Aspose.PDF.Model.TextReplace body = new Com.Aspose.PDF.Model.TextReplace(); body.OldValue = "Sample PDF"; body.NewValue = "This is the new test added by IA"; try { // Upload source file to aspose cloud storage storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName)); // Invoke Aspose.PDF Cloud SDK API to replace pdf text DocumentTextReplaceResponse apiResponse = pdfApi.PostDocumentReplaceText(fileName, storage, folder, body); if (apiResponse != null && apiResponse.Status.Equals("OK")) { Console.WriteLine("Replace PDF Document Text, Done!"); Console.ReadKey(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); } // ExEnd:1 }
public static void Run() { // ExStart:1 PdfApi pdfApi = new PdfApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); string fileName = "test.pdf"; int? pageNumber = 1; string storage = null; string folder = null; Com.Aspose.PDF.Model.TextReplaceListRequest body = new Com.Aspose.PDF.Model.TextReplaceListRequest(); Com.Aspose.PDF.Model.TextReplace tr = new Com.Aspose.PDF.Model.TextReplace(); tr.NewValue = "This will be the new text"; body.TextReplaces = new System.Collections.Generic.List <Com.Aspose.PDF.Model.TextReplace> { tr }; try { // Upload source file to aspose cloud storage storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName)); // Invoke Aspose.PDF Cloud SDK API to replace pdf document page text list PageTextReplaceResponse apiResponse = pdfApi.PostPageReplaceTextList(fileName, pageNumber, storage, folder, body); if (apiResponse != null && apiResponse.Status.Equals("OK")) { Console.WriteLine("PDF Document Page Replace Text List, Done!"); Console.ReadKey(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); } // ExEnd:1 }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="pageNumber"></param> /// <param name="storage"></param> /// <param name="folder"></param> /// <param name="body"></param> /// <returns></returns> public PageTextReplaceResponse PostPageReplaceText(string name, int? pageNumber, string storage, string folder, TextReplace body) { // create path and map variables var ResourcePath = "/pdf/{name}/pages/{pageNumber}/replaceText/?appSid={appSid}&storage={storage}&folder={folder}".Replace("{format}","json"); ResourcePath = Regex.Replace(ResourcePath, "\\*", "").Replace("&", "&").Replace("/?", "?").Replace("toFormat={toFormat}", "format={format}"); // query params var queryParams = new Dictionary<String, String>(); var headerParams = new Dictionary<String, String>(); var formParams = new Dictionary<String, object>(); // verify required params are set if (name == null || pageNumber == null || body == null ) { throw new ApiException(400, "missing required params"); } if (name == null){ ResourcePath = Regex.Replace(ResourcePath, @"([&?])name=", ""); }else{ ResourcePath = ResourcePath.Replace("{" + "name" + "}", apiInvoker.ToPathValue(name)); } if (pageNumber == null){ ResourcePath = Regex.Replace(ResourcePath, @"([&?])pageNumber=", ""); }else{ ResourcePath = ResourcePath.Replace("{" + "pageNumber" + "}", apiInvoker.ToPathValue(pageNumber)); } if (storage == null){ ResourcePath = Regex.Replace(ResourcePath, @"([&?])storage=", ""); }else{ ResourcePath = ResourcePath.Replace("{" + "storage" + "}", apiInvoker.ToPathValue(storage)); } if (folder == null){ ResourcePath = Regex.Replace(ResourcePath, @"([&?])folder=", ""); }else{ ResourcePath = ResourcePath.Replace("{" + "folder" + "}", apiInvoker.ToPathValue(folder)); } try { if (typeof(PageTextReplaceResponse) == typeof(ResponseMessage)) { var response = apiInvoker.invokeBinaryAPI(basePath, ResourcePath, "POST", queryParams, null, headerParams, formParams); return (PageTextReplaceResponse) ApiInvoker.deserialize(response, typeof(PageTextReplaceResponse)); } else { var response = apiInvoker.invokeAPI(basePath, ResourcePath, "POST", queryParams, body, headerParams, formParams); if(response != null){ return (PageTextReplaceResponse) ApiInvoker.deserialize(response, typeof(PageTextReplaceResponse)); } else { return null; } } } catch (ApiException ex) { if(ex.ErrorCode == 404) { return null; } else { throw ex; } } }