Split Word Documents (PHP REST)

Skip to end of metadata
Go to start of metadata
This example allows you to split all or specific pages of a Word document and save each page as PDF, Image or any supported format using Saaspose.Words REST API in your PHP applications.


Split all pages to new documents

SaasposeApp::$AppSID  = "77***************************";
SaasposeApp::$AppKey = "9a******************************";
SaasposeApp::$OutPutLocation = getcwd() . "\\Output\\";

//build URI to split page
$strURI = 'http://api.saaspose.com/v1.0/words/Sample.doc/split'; 

//sign URI
$signedURI = Utils::Sign($strURI);

$responseStream = Utils::processCommand($signedURI, "POST", "", "");
$json = json_decode($responseStream);

//iterate throug each document in the result to find output pages
foreach ($json->SplitResult->Pages as $splitPage) { 
	$splitFileName = basename($splitPage->Href);
	
	//build URI to download split pages 
	$strURI = 'http://api.saaspose.com/v1.0/storage/file/' . $splitFileName;
	
	//sign URI
	$signedURI = Utils::Sign($strURI);

	$responseStream = Utils::processCommand($signedURI, "GET", "", "");
	//save output file
	$outputFile = SaasposeApp::$OutPutLocation . $splitFileName;
	Utils::saveFile($responseStream, $outputFile);
}

Split specific pages to new documents

SaasposeApp::$AppSID  = "77***************************";
SaasposeApp::$AppKey = "9a******************************";
SaasposeApp::$OutPutLocation = getcwd() . "\\Output\\";

//build URI to split page
$strURI = 'http://api.saaspose.com/v1.0/words/Sample.doc/split?from=2&to=3'; 

//sign URI
$signedURI = Utils::Sign($strURI);

$responseStream = Utils::processCommand($signedURI, "POST", "", "");
$json = json_decode($responseStream);

//iterate throug each document in the result to find output pages
foreach ($json->SplitResult->Pages as $splitPage) { 
	$splitFileName = basename($splitPage->Href);
	
	//build URI to download split pages 
	$strURI = 'http://api.saaspose.com/v1.0/storage/file/' . $splitFileName;
	
	//sign URI
	$signedURI = Utils::Sign($strURI);

	$responseStream = Utils::processCommand($signedURI, "GET", "", "");
	//save output file
	$outputFile = SaasposeApp::$OutPutLocation . $splitFileName;
	Utils::saveFile($responseStream, $outputFile);
}

Split pages to any supported format

SaasposeApp::$AppSID  = "77***************************";
SaasposeApp::$AppKey = "9a******************************";
SaasposeApp::$OutPutLocation = getcwd() . "\\Output\\";

//build URI to split page
$strURI = 'http://api.saaspose.com/v1.0/words/Sample.doc/split?format=png'; 

//sign URI
$signedURI = Utils::Sign($strURI);

$responseStream = Utils::processCommand($signedURI, "POST", "", "");
$json = json_decode($responseStream);

//iterate throug each document in the result to find output pages
foreach ($json->SplitResult->Pages as $splitPage) { 
	$splitFileName = basename($splitPage->Href);
	
	//build URI to download split pages 
	$strURI = 'http://api.saaspose.com/v1.0/storage/file/' . $splitFileName;
	
	//sign URI
	$signedURI = Utils::Sign($strURI);

	$responseStream = Utils::processCommand($signedURI, "GET", "", "");
	//save output file
	$outputFile = SaasposeApp::$OutPutLocation . $splitFileName;
	Utils::saveFile($responseStream, $outputFile);
}

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.