Move PDF Pages to New Locations in a PDF File Introduction
This example allows you to move pages to new locations in a PDF file using Aspose.PDF for Cloud API in your applications. The API has the following properties
API
Type
Description
/pdf/{name}/pages/{pageNumber}/movePage
POST
Move the page mentioned in the pageNumber parameter to a new location in the PDF Page
The API has the following parameters
Parameter
Requiered
Description
Type
Data Type
name
Yes
The name of the document containing the source page
Path
String
pageNumber
Yes
The source page number for the move operation
Path
String
newIndex
Yes
The destination page number for the move operation
Query
String
Resource
The following Aspose.PDF Cloud REST API resource has been used in the examples: Move Page .
cURL Example
SDK Source
The Aspose for Cloud SDKs can be downloaded from the following page: Available SDKs
SDK Examples
Move PDF pages to new Location
C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Cloud
PdfApi pdfApi = new PdfApi("API_KEY", "APP_SID");
String fileName = "sample-merged.pdf";
int pageNumber = 1;
int newIndex = 2;
String storage = "";
String folder = "";
try
{
// Upload source file to aspose cloud storage
pdfApi.UploadFile(fileName, System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));
// Invoke Aspose.PDF Cloud SDK API to move pages to new location
SaaSposeResponse apiResponse = pdfApi.PostMovePage(fileName, pageNumber, newIndex, storage, folder);
if (apiResponse != null && apiResponse.Status.Equals("OK"))
{
Console.WriteLine("Move PDF Pages to New Locations in a PDF File, Done!");
Console.ReadKey();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Cloud
String fileName = "sample-merged.pdf";
int pageNumber = 1;
int newIndex = 2;
String storage = "";
String folder = "";
Path inputFile = Utils.getPath(MovePDFToNewLocation.class, fileName);
try
{
// Instantiate Aspose Words API SDK
PdfApi pdfApi = new PdfApi(Configuration.apiKey, Configuration.appSID);
// Upload source file to aspose cloud storage
pdfApi.uploadFile(fileName, inputFile.toFile(),null);
// Invoke Aspose.PDF Cloud SDK API to move pages to new location
SaaSposeResponse apiResponse = pdfApi.PostMovePage(fileName, pageNumber, newIndex, storage, folder);
if (apiResponse != null && apiResponse.getStatus().equals("OK"))
{
System.out.println("Move PDF Pages to New Locations in a PDF File, Done!");
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Cloud
<?php
require_once realpath(__DIR__ . '/..') . '/vendor/autoload.php';
require_once realpath(__DIR__ . '/..') . '/Utils.php';
use Aspose\PDF\PdfApi;
use Aspose\PDF\AsposeApp;
class Pages {
public $pdfApi;
public function __construct() {
AsposeApp::$appSID = Utils::appSID;
AsposeApp::$apiKey = Utils::apiKey;
$this->pdfApi = new PdfApi();
}
public function postMovePage() {
// Upload file to Aspose Cloud Storage
$fileName = "sample-merged.pdf";
Utils::uploadFile($fileName);
$result = $this->pdfApi->PostMovePage($fileName, $pageNumber = 1, $newIndex = 1, $storage = "", $folder = "");
print_r ( $result );
}
}
$pages = new Pages();
$pages->postMovePage();
?>