Last active
February 12, 2019 08:42
-
-
Save aspose-cloud/d33e07e49426e4f66a3262788d9792a3 to your computer and use it in GitHub Desktop.
The GIST contains PHP Examples of Aspose.Words Cloud APIs.
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-words-cloud/aspose-words-cloud-php | |
<?php | |
require_once realpath(__DIR__ . '/..') . '/vendor/autoload.php'; | |
use Aspose\Storage\Api\StorageApi; | |
use Aspose\Words\Configuration; | |
use Aspose\Words\WordsApi; | |
use Aspose\Words\Model\Requests; | |
use Aspose\Words\Model\SaveOptionsData; | |
use Aspose\Words\Model\DocumentEntryList; | |
use Aspose\Words\Model\DocumentEntry; | |
class Document { | |
public $wordsApi; | |
public $storageApi; | |
public function __construct() { | |
#$BaseUrl = "https://api.aspose.cloud/v1.1/"; | |
$AppKey = ""; // Get AppKey and AppSID from https://dashboard.aspose.cloud/ | |
$AppSid = ""; // Get AppKey and AppSID from https://dashboard.aspose.cloud/ | |
$config = new Configuration(); | |
$config->setAppKey($AppKey)->setAppSid($AppSid); | |
$this->wordsApi = new WordsApi(null, $config); | |
$this->storageApi = new StorageApi(); | |
$this->storageApi->getConfig()->setAppKey($AppKey)->setAppSid($AppSid);//->setHost($BaseUrl); | |
} | |
public function uploadFile($fileName) { | |
$file = realpath(__DIR__ . '/../..') . '/TestData/Common/' . $fileName; | |
$putRequest = new Aspose\Storage\Model\Requests\PutCreateRequest($fileName, $file); | |
$this->storageApi->PutCreate($putRequest); | |
} | |
public function appendDocument() { | |
$fileName = "test_doc.docx"; | |
$documentToAppend = "test_multi_pages.docx"; | |
$folder = null; // Input file exists at the root of the storage | |
$destFileName = null; // Changes will be made in the source docuemnt | |
// Upload source document to Cloud Storage | |
$this->uploadFile($fileName); | |
// Upload document to append to Cloud Storage | |
$this->uploadFile($documentToAppend); | |
$documentList = new DocumentEntryList(); | |
$docEntry = new DocumentEntry(array("href" => $documentToAppend, "import_format_mode" => "KeepSourceFormatting")); | |
$documentList->setDocumentEntries(array($docEntry)); | |
$request = new Requests\PostAppendDocumentRequest($fileName, $documentList, $folder, null, null, null, $destName, null, null); | |
$result = $this->wordsApi->postAppendDocument($request); | |
print_r($result); | |
} | |
} | |
$document = new Document(); | |
$document->appendDocument(); | |
?> |
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
The GIST contains PHP Examples of Aspose.Words Cloud APIs. |
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-words-cloud/aspose-words-cloud-php | |
<?php | |
require_once realpath(__DIR__) . '/vendor/autoload.php'; | |
use Aspose\Storage\Api\StorageApi; | |
use Aspose\Words\WordsApi; | |
use Aspose\Words\Model\Requests; | |
use Aspose\Words\Model\SaveOptionsData; | |
class Document { | |
public $wordsApi; | |
public $storageApi; | |
public function __construct() { | |
$storageConfig = new Aspose\Storage\Configuration(); | |
# Get App Key and App SID from https://dashboard.aspose.cloud/ | |
$storageConfig->setAppKey('')->setAppSid(''); | |
$this->storageApi = new StorageApi($storageConfig); | |
$wordsConfig = new Aspose\Words\Configuration(); | |
# Get App Key and App SID from https://dashboard.aspose.cloud/ | |
$wordsConfig->setAppKey('')->setAppSid(''); | |
$this->wordsApi = new WordsApi(null, $wordsConfig); | |
} | |
public function convertHTMLToWord() { | |
$fileName = "html_example.html"; | |
$file = realpath(__DIR__) . '/Data/' . $fileName; | |
# Upload file to Cloud Storage | |
$putRequest = new Aspose\Storage\Model\Requests\PutCreateRequest($fileName, $file); | |
$this->storageApi->PutCreate($putRequest); | |
# Convert HTML file to Word | |
$destName = "html_example.docx"; | |
$saveOptions = new SaveOptionsData(array("save_format" => "docx", "file_name" => $destName)); | |
$request = new Requests\PostDocumentSaveAsRequest($fileName, $saveOptions); | |
$result = $this->wordsApi->postDocumentSaveAs($request); | |
print "The HTML file successfully converted to Word!" . PHP_EOL; | |
} | |
} | |
$document = new Document(); | |
$document->convertHTMLToWord(); | |
?> |
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-words-cloud/aspose-words-cloud-php | |
<?php | |
require_once realpath(__DIR__ . '/..') . '/vendor/autoload.php'; | |
use Aspose\Storage\Api\StorageApi; | |
use Aspose\Words\WordsApi; | |
class Classification { | |
public $wordsApi; | |
public $storageApi; | |
public function __construct() { | |
$storageConfig = new Aspose\Storage\Configuration(); | |
# Get App Key and App SID from https://dashboard.aspose.cloud/ | |
$storageConfig->setAppKey('App Key')->setAppSid('App SID'); | |
$this->storageApi = new StorageApi($storageConfig); | |
$wordsConfig = new Aspose\Words\Configuration(); | |
# Get App Key and App SID from https://dashboard.aspose.cloud/ | |
$wordsConfig->setAppKey('App Key')->setAppSid('App SID'); | |
$this->wordsApi = new WordsApi(null, $wordsConfig); | |
} | |
public function classifyDocument() { | |
$fileName = "test_multi_pages.docx"; | |
$file = realpath(__DIR__ . '/..') . '/Data/' . $fileName; | |
$putRequest = new Aspose\Storage\Model\Requests\PutCreateRequest($fileName, $file); | |
$this->storageApi->PutCreate($putRequest); | |
$request = new Aspose\Words\Model\Requests\ClassifyDocumentRequest($fileName, null, null, null, null, $best_classes_count = 1); | |
$result = $this->wordsApi->classifyDocument($request); | |
} | |
} | |
$classification = new Classification(); | |
$classification->classifyDocument(); | |
?> |
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-words-cloud/aspose-words-cloud-php | |
<?php | |
require_once realpath(__DIR__ . '/..') . '/vendor/autoload.php'; | |
use Aspose\Words\WordsApi; | |
class Classification { | |
public $wordsApi; | |
public function __construct() { | |
$wordsConfig = new Aspose\Words\Configuration(); | |
# Get App Key and App SID from https://dashboard.aspose.cloud/ | |
$wordsConfig->setAppKey('App Key')->setAppSid('App SID'); | |
$this->wordsApi = new WordsApi(null, $wordsConfig); | |
} | |
public function classifyRawText() { | |
$request = new Aspose\Words\Model\Requests\ClassifyRequest("Try text classification", "3"); | |
$result = $this->wordsApi->classify($request); | |
} | |
} | |
$classification = new Classification(); | |
$classification->classifyRawText(); | |
?> |
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-words-cloud/aspose-words-cloud-php | |
<?php | |
require_once realpath(__DIR__ . '/..') . '/vendor/autoload.php'; | |
use Aspose\Storage\Api\StorageApi; | |
use Aspose\Words\Configuration; | |
use Aspose\Words\WordsApi; | |
use Aspose\Words\Model\Requests; | |
use Aspose\Words\Model\SaveOptionsData; | |
use Aspose\Words\Model\DocumentEntryList; | |
use Aspose\Words\Model\DocumentEntry; | |
class Document { | |
public $wordsApi; | |
public $storageApi; | |
public function __construct() { | |
#$BaseUrl = "https://api.aspose.cloud/v1.1/"; | |
$AppKey = ""; // Get AppKey and AppSID from https://dashboard.aspose.cloud/ | |
$AppSid = ""; // Get AppKey and AppSID from https://dashboard.aspose.cloud/ | |
$config = new Configuration(); | |
$config->setAppKey($AppKey)->setAppSid($AppSid); | |
$this->wordsApi = new WordsApi(null, $config); | |
$this->storageApi = new StorageApi(); | |
$this->storageApi->getConfig()->setAppKey($AppKey)->setAppSid($AppSid);//->setHost($BaseUrl); | |
} | |
public function uploadFile($fileName) { | |
$file = realpath(__DIR__ . '/../..') . '/TestData/Common/' . $fileName; | |
$putRequest = new Aspose\Storage\Model\Requests\PutCreateRequest($fileName, $file); | |
$this->storageApi->PutCreate($putRequest); | |
} | |
public function splitAllPagesToNewPDFs() { | |
$fileName = "test_multi_pages.docx"; | |
$format = "pdf"; | |
$from = null; // Splitting starts from the first page of the document | |
$to = null; // splitting ends at the last page of the document | |
$folder = null; // Input file exists at the root of the storage | |
$destName = null; | |
// Upload source document to Cloud Storage | |
$this->uploadFile($fileName); | |
$request = new Requests\PostSplitDocumentRequest($fileName, $folder, null, null, null, $destName, $format, $from, $to); | |
$result = $this->wordsApi->postSplitDocument($request); | |
print_r($result); | |
} | |
} | |
$document = new Document(); | |
$document->splitAllPagesToNewPDFs(); | |
?> |
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-words-cloud/aspose-words-cloud-php | |
<?php | |
require_once realpath(__DIR__ . '/..') . '/vendor/autoload.php'; | |
use Aspose\Storage\Api\StorageApi; | |
use Aspose\Words\Configuration; | |
use Aspose\Words\WordsApi; | |
use Aspose\Words\Model\Requests; | |
use Aspose\Words\Model\SaveOptionsData; | |
use Aspose\Words\Model\DocumentEntryList; | |
use Aspose\Words\Model\DocumentEntry; | |
class Document { | |
public $wordsApi; | |
public $storageApi; | |
public function __construct() { | |
#$BaseUrl = "https://api.aspose.cloud/v1.1/"; | |
$AppKey = ""; // Get AppKey and AppSID from https://dashboard.aspose.cloud/ | |
$AppSid = ""; // Get AppKey and AppSID from https://dashboard.aspose.cloud/ | |
$config = new Configuration(); | |
$config->setAppKey($AppKey)->setAppSid($AppSid); | |
$this->wordsApi = new WordsApi(null, $config); | |
$this->storageApi = new StorageApi(); | |
$this->storageApi->getConfig()->setAppKey($AppKey)->setAppSid($AppSid);//->setHost($BaseUrl); | |
} | |
public function uploadFile($fileName) { | |
$file = realpath(__DIR__ . '/../..') . '/TestData/Common/' . $fileName; | |
$putRequest = new Aspose\Storage\Model\Requests\PutCreateRequest($fileName, $file); | |
$this->storageApi->PutCreate($putRequest); | |
} | |
public function splitSpecificPagesToNewPDFs() { | |
$fileName = "test_multi_pages.docx"; | |
$format = "pdf"; | |
$from = 1; // Splitting starts from the first page of the document | |
$to = 2; // splitting ends at the second page of the document | |
$folder = null; // Input file exists at the root of the storage | |
$destName = null; | |
// Upload source document to Cloud Storage | |
$this->uploadFile($fileName); | |
$request = new Requests\PostSplitDocumentRequest($fileName, $folder, null, null, null, $destName, $format, $from, $to); | |
$result = $this->wordsApi->postSplitDocument($request); | |
print_r($result); | |
} | |
} | |
$document = new Document(); | |
$document->splitSpecificPagesToNewPDFs(); | |
?> |
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-words-cloud/aspose-words-cloud-php | |
<?php | |
require_once realpath(__DIR__ . '/..') . '/vendor/autoload.php'; | |
use Aspose\Storage\Api\StorageApi; | |
use Aspose\Words\Configuration; | |
use Aspose\Words\WordsApi; | |
use Aspose\Words\Model\Requests; | |
use Aspose\Words\Model\SaveOptionsData; | |
use Aspose\Words\Model\DocumentEntryList; | |
use Aspose\Words\Model\DocumentEntry; | |
class Document { | |
public $wordsApi; | |
public $storageApi; | |
public function __construct() { | |
#$BaseUrl = "https://api.aspose.cloud/v1.1/"; | |
$AppKey = ""; // Get AppKey and AppSID from https://dashboard.aspose.cloud/ | |
$AppSid = ""; // Get AppKey and AppSID from https://dashboard.aspose.cloud/ | |
$config = new Configuration(); | |
$config->setAppKey($AppKey)->setAppSid($AppSid); | |
$this->wordsApi = new WordsApi(null, $config); | |
$this->storageApi = new StorageApi(); | |
$this->storageApi->getConfig()->setAppKey($AppKey)->setAppSid($AppSid);//->setHost($BaseUrl); | |
} | |
public function uploadFile($fileName) { | |
$file = realpath(__DIR__ . '/../..') . '/TestData/Common/' . $fileName; | |
$putRequest = new Aspose\Storage\Model\Requests\PutCreateRequest($fileName, $file); | |
$this->storageApi->PutCreate($putRequest); | |
} | |
public function splitSpecificPagesToPNGs() { | |
$fileName = "test_multi_pages.docx"; | |
$format = "png"; | |
$from = 1; // Splitting starts from the first page of the document | |
$to = 2; // splitting ends at the second page of the document | |
$folder = null; // Input file exists at the root of the storage | |
$zip_output = true; | |
$destName = "test_multi_pages.zip"; | |
// Upload source document to Cloud Storage | |
$this->uploadFile($fileName); | |
$request = new Requests\PostSplitDocumentRequest($fileName, $folder, null, null, null, $destName, $format, $from, $to, $zip_output); | |
$result = $this->wordsApi->postSplitDocument($request); | |
print_r($result); | |
} | |
} | |
$document = new Document(); | |
$document->splitSpecificPagesToPNGs(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment