Replace Text without Using a Storage Introduction
You don’t need to upload files to storage to perform text replacement. You can use online methods to read a presentation from a request body and return an updated one in a response body. As with storage methods, Aspose.Slides Cloud provides methods to replace text on a specified slide or in the presentation as a whole. With online methods, the result of the operation is the updated presentation. The number of replacements is not returned. You need to use storage methods if replacement count is essential information for you.
ReplacePresentationTextOnline
Request Parameters
Name
Type
Location
Required
Description
document
file
formData
true
The presentation file.
oldValue
string
query
true
The text to be replaced.
newValue
string
query
true
The text to replace with.
ignoreCase
boolean
query
false
If true
, the character case must be ignored. The default is false
.
wholeWordsOnly
boolean
query
false
Indicates whether to replace only whole words that match the replace string. False by default.
password
string
header
false
The password to open the presentation.
In case of Amazon S3 storage folder path starts with Amazon S3 bucket name.
Examples
Replace the word banana with the word orange in the document MyPresentation.pptx . Ignore the case of text characters.
cURL Solution
We are using the /slides/replaceText resource for the example. You can use the /slides/slides/{slideIndex}/replaceText with the same query parameters to replace all matching occurrences of the text items on a specific slide in a PowerPoint presentation.
SDK Solutions
C#
SlidesApi api = new SlidesApi ( "MyClientId" , "MyClientSecret" );
using Stream documentStream = File . OpenRead ( "MyPresentation.pptx" );
using Stream resultStream = api . ReplacePresentationTextOnline ( documentStream , "banana" , "orange" , true );
using Stream outputStream = File . OpenWrite ( "UpdatedPresentation.pptx" );
resultStream . CopyTo ( outputStream );
Java
SlidesApi api = new SlidesApi ( "MyClientId" , "MyClientSecret" );
byte [] documentData = Files . readAllBytes ( Paths . get ( "MyPresentation.pptx" ));
File resultFile = api . replacePresentationTextOnline ( documentData , "banana" , "orange" , true , null , null );
System . out . println ( "The updated file was saved to " + resultFile . getPath ());
PHP
use Aspose\Slides\Cloud\Sdk\Api\Configuration ;
use Aspose\Slides\Cloud\Sdk\Api\SlidesApi ;
$config = new Configuration ();
$config -> setAppSid ( "MyClientId" );
$config -> setAppKey ( "MyClientSecret" );
$api = new SlidesApi ( null , $config );
$documentStream = fopen ( "MyPresentation.pptx" , "r" );
$resultFile = $api -> ReplacePresentationTextOnline ( $documentStream , "banana" , "orange" , true );
print ( "The updated file was saved to " . $resultFile -> getPathname ());
Ruby
require "aspose_slides_cloud"
include AsposeSlidesCloud
configuration = Configuration . new
configuration . app_sid = "MyClientId"
configuration . app_key = "MyClientSecret"
slides_api = SlidesApi . new ( configuration )
document_data = File . binread ( "MyPresentation.pptx" )
result_data = slides_api . replace_presentation_text_online ( document_data , "banana" , "orange" , true )
File . binwrite ( "UpdatedPresentation.pptx" , result_data )
Python
import asposeslidescloud
from asposeslidescloud.configuration import Configuration
from asposeslidescloud.apis.slides_api import SlidesApi
configuration = Configuration ()
configuration . app_sid = "MyClientId"
configuration . app_key = "MyClientSecret"
api = SlidesApi ( configuration )
with open ( "MyPresentation.pptx" , "rb" ) as f :
document_data = f . read ()
result_file_path = api . replace_presentation_text_online ( document_data , "banana" , "orange" , True )
print ( "The updated file was saved to " + result_file_path )
Node.js
const cloudSdk = require ( "asposeslidescloud" );
const fs = require ( "fs" );
const api = new cloudSdk . SlidesApi ( "MyClientId" , "MyClientSecret" );
const documentStream = fs . createReadStream ( "MyPresentation.pptx" );
api . replacePresentationTextOnline ( documentStream , "banana" , "orange" , true ). then ( response => {
fs . writeFile ( "UpdatedPresentation.pptx" , response . body , ( error ) => {
if ( error ) throw error ;
});
});
C++
#include "asposeslidescloud/api/SlidesApi.h"
using namespace asposeslidescloud :: api ;
int main ()
{
auto slidesApi = std :: make_shared < SlidesApi > ( L "MyClientId" , L "MyClientSecret" );
auto documentStream = std :: make_shared < std :: ifstream > ( "MyPresentation.pptx" , std :: ios :: binary );
auto documentContent = std :: make_shared < HttpContent > ();
documentContent -> setData ( documentStream );
auto resultContent = slidesApi -> replacePresentationTextOnline ( documentContent , L "banana" , L "orange" , true ). get ();
std :: ofstream outputStream ( "UpdatedPresentation.pptx" , std :: ofstream :: binary );
resultContent . writeTo ( outputStream );
}
Perl
use File::Slurp ;
use AsposeSlidesCloud::Configuration ;
use AsposeSlidesCloud::SlidesApi ;
my $config = AsposeSlidesCloud::Configuration -> new ();
$config -> { app_sid } = "MyClientId" ;
$config -> { app_key } = "MyClientSecret" ;
my $slides_api = AsposeSlidesCloud::SlidesApi -> new ( config => $config );
my $document_data = read_file ( "MyPresentation.pptx" , { binmode => ":raw" });
my %parameters = ( document => $document_data , old_value => "banana" , new_value => "orange" , ignore_case => 1 );
my $result_data = $slides_api -> replace_presentation_text_online ( %parameters );
write_file ( "UpdatedPresentation.pptx" , { binmode => ":raw" }, $result_data );
Go
cfg := asposeslidescloud . NewConfiguration ()
cfg . AppSid = "MyClientId"
cfg . AppKey = "MyClientSecret"
api := asposeslidescloud . NewAPIClient ( cfg )
source , e := ioutil . ReadFile ( "MyPresentation.pptx" )
if e != nil {
fmt . Printf ( "Error: %v." , e )
return
}
var ignoreCase bool = true
result , _ , e := api . SlidesApi . ReplacePresentationTextOnline ( source , "banana" , "orange" , & ignoreCase , nil , "" )
if e != nil {
fmt . Printf ( "Error: %v." , e )
return
}
fmt . Printf ( "The updated file was saved to %v." , result . Name ())
Swift
ReplacePresentationRegexOnline
API
Type
Description
Resource
/slides/replaceRegex
POST
Replaces text in a presentation that matches a specified regular expression.
ReplacePresentationRegexOnline
Request Parameters
Name
Type
Location
Required
Description
document
file
formData
true
The presentation file.
pattern
string
query
true
The regular expression to be replaced.
newValue
string
query
true
The text to replace with.
ignoreCase
boolean
query
false
If true
, the character case must be ignored. The default is false
.
password
string
header
false
The password to open the presentation.
In case of Amazon S3 storage folder path starts with Amazon S3 bucket name.
Examples
Replace every occurence of hello , hi or hey with hola in the document MyPresentation.pptx . Ignore the case of text characters.
cURL Solution
SDK Solutions
C#
SlidesApi api = new SlidesApi ( "MyClientId" , "MyClientSecret" );
using Stream documentStream = File . OpenRead ( "MyPresentation.pptx" );
using Stream resultStream = api . ReplacePresentationRegexOnline ( documentStream , "\\b(hello|hi|hey)\\b" , "hola" , true );
using Stream outputStream = File . OpenWrite ( "UpdatedPresentation.pptx" );
resultStream . CopyTo ( outputStream );
Java
SlidesApi api = new SlidesApi ( "MyClientId" , "MyClientSecret" );
byte [] documentData = Files . readAllBytes ( Paths . get ( "MyPresentation.pptx" ));
File resultFile = api . replacePresentationRegexOnline ( documentData , "\\b(hello|hi|hey)\\b" , "hola" , true , null );
System . out . println ( "The updated file was saved to " + resultFile . getPath ());
PHP
use Aspose\Slides\Cloud\Sdk\Api\Configuration ;
use Aspose\Slides\Cloud\Sdk\Api\SlidesApi ;
$config = new Configuration ();
$config -> setAppSid ( "MyClientId" );
$config -> setAppKey ( "MyClientSecret" );
$api = new SlidesApi ( null , $config );
$documentStream = fopen ( "MyPresentation.pptx" , "r" );
$resultFile = $api -> ReplacePresentationRegexOnline ( $documentStream , " \\ b(hello|hi|hey) \\ b" , "hola" , true );
print ( "The updated file was saved to " . $resultFile -> getPathname ());
Ruby
require "aspose_slides_cloud"
include AsposeSlidesCloud
configuration = Configuration . new
configuration . app_sid = "MyClientId"
configuration . app_key = "MyClientSecret"
slides_api = SlidesApi . new ( configuration )
document_data = File . binread ( "MyPresentation.pptx" )
result_data = slides_api . replace_presentation_regex_online ( document_data , " \\ b(hello|hi|hey) \\ b" , "hola" , true )
File . binwrite ( "UpdatedPresentation.pptx" , result_data )
Python
import asposeslidescloud
from asposeslidescloud.configuration import Configuration
from asposeslidescloud.apis.slides_api import SlidesApi
configuration = Configuration ()
configuration . app_sid = "MyClientId"
configuration . app_key = "MyClientSecret"
api = SlidesApi ( configuration )
with open ( "MyPresentation.pptx" , "rb" ) as f :
document_data = f . read ()
result_file_path = api . replace_presentation_regex_online ( document_data , " \\ b(hello|hi|hey) \\ b" , "hola" , True )
print ( "The updated file was saved to " + result_file_path )
Node.js
const cloudSdk = require ( "asposeslidescloud" );
const fs = require ( "fs" );
const api = new cloudSdk . SlidesApi ( "MyClientId" , "MyClientSecret" );
const documentStream = fs . createReadStream ( "MyPresentation.pptx" );
api . replacePresentationRegexOnline ( documentStream , "\\b(hello|hi|hey)\\b" , "hola" , true ). then ( response => {
fs . writeFile ( "UpdatedPresentation.pptx" , response . body , ( error ) => {
if ( error ) throw error ;
});
});
C++
#include "asposeslidescloud/api/SlidesApi.h"
using namespace asposeslidescloud :: api ;
int main ()
{
auto slidesApi = std :: make_shared < SlidesApi > ( L "MyClientId" , L "MyClientSecret" );
auto documentStream = std :: make_shared < std :: ifstream > ( "MyPresentation.pptx" , std :: ios :: binary );
auto documentContent = std :: make_shared < HttpContent > ();
documentContent -> setData ( documentStream );
auto resultContent = slidesApi -> replacePresentationRegexOnline ( documentContent , L " \\ b(hello|hi|hey) \\ b" , L "hola" , true ). get ();
std :: ofstream outputStream ( "UpdatedPresentation.pptx" , std :: ofstream :: binary );
resultContent . writeTo ( outputStream );
}
Perl
use File::Slurp ;
use AsposeSlidesCloud::Configuration ;
use AsposeSlidesCloud::SlidesApi ;
my $config = AsposeSlidesCloud::Configuration -> new ();
$config -> { app_sid } = "MyClientId" ;
$config -> { app_key } = "MyClientSecret" ;
my $slides_api = AsposeSlidesCloud::SlidesApi -> new ( config => $config );
my $document_data = read_file ( "MyPresentation.pptx" , { binmode => ":raw" });
my %parameters = ( document => $document_data , pattern => "banana" , new_value => "orange" , ignore_case => 1 );
my $result_data = $slides_api -> replace_presentation_regex_online ( %parameters );
write_file ( "UpdatedPresentation.pptx" , { binmode => ":raw" }, $result_data );
Go
cfg := asposeslidescloud . NewConfiguration ()
cfg . AppSid = "MyClientId"
cfg . AppKey = "MyClientSecret"
api := asposeslidescloud . NewAPIClient ( cfg )
source , e := ioutil . ReadFile ( "MyPresentation.pptx" )
if e != nil {
fmt . Printf ( "Error: %v." , e )
return
}
var ignoreCase bool = true
result , _ , e := api . SlidesApi . ReplacePresentationRegexOnline ( source , "\\b(hello|hi|hey)\\b" , "hola" , & ignoreCase , "" )
if e != nil {
fmt . Printf ( "Error: %v." , e )
return
}
fmt . Printf ( "The updated file was saved to %v." , result . Name ())
ReplaceSlideTextOnline
API
Type
Description
Resource
/slides/slides/{slideIndex}/replaceText
POST
Replaces text within a specified presentation slide.
ReplaceSlideTextOnline
Request Parameters
Name
Type
Location
Required
Description
document
file
formData
true
The presentation file.
slideIndex
integer
path
true
The 1-based index of the slide.
oldValue
string
query
true
The text to be replaced.
newValue
string
query
true
The text to replace with.
ignoreCase
boolean
query
false
If true
, the character case must be ignored. The default is false
.
password
string
header
false
The password to open the presentation.
In case of Amazon S3 storage folder path starts with Amazon S3 bucket name.
SDKs
Check Available SDKs to learn how to add an SDK to your project.