/** * Saves a particular slide into various formats with specified width and height */ public function convertToImagebySize($fileName, $saveFormat = 'PPT', $slideNumber, $imageFormat, $width, $height) { try { $strURI = Product::$baseProductUri . "/slides/" . $this->fileName . "/slides/" . $slideNumber . "?format=" . $imageFormat . "&width=" . $width . "&height=" . $height; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); Utils::saveFile($responseStream, SaasposeApp::$outputLocation . "output." . $imageFormat); } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * reads all or specific barcodes from images * @param string $symbology */ public function read($symbology) { try { //build URI to read barcode $strURI = Product::$baseProductUri . "/barcode/" . $this->fileName . "/recognize?" . (!isset($symbology) || trim($symbology) === '' ? "type=" : "type=" . $symbology); //sign URI $signedURI = Utils::sign($strURI); //get response stream $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $json = json_decode($responseStream); //returns a list of extracted barcodes return $json->Barcodes; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Get the particular image from the specified page with the default image size * @param int $pageNumber * @param int $imageIndex * @param string $imageFormat * @param int $imageWidth * @param int $imageHeight */ public function getImageCustomSize($pageNumber, $imageIndex, $imageFormat, $imageWidth, $imageHeight) { try { $strURI = Product::$baseProductUri . "/pdf/" . $this->fileName . "/pages/" . $pageNumber . "/images/" . $imageIndex . "?format=" . $imageFormat . "&width=" . $imageWidth . "&height=" . $imageHeight; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { Utils::saveFile($responseStream, SaasposeApp::$outputLocation . Utils::getFileName($this->fileName) . "_" . $imageIndex . "." . $imageFormat); return ""; } else { return $v_output; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * generates new barcodes with specific text, symbology, image format, resolution and dimensions * @param string $codeText * @param string $symbology * @param string $imageFormat * @param string $xResolution * @param string $yResolution * @param string $xDimension * @param string $yDimension */ public function save($codeText, $symbology, $imageFormat, $xResolution, $yResolution, $xDimension, $yDimension) { //build URI to generate barcode $strURI = Product::$baseProductUri . "/barcode/generate?text=" . $codeText . "&type=" . $symbology . "&format=" . $imageFormat . ($xResolution <= 0 ? "" : "&resolutionX=" . $xResolution) . ($yResolution <= 0 ? "" : "&resolutionY=" . $yResolution) . ($xDimension <= 0 ? "" : "&dimensionX=" . $xDimension) . ($yDimension <= 0 ? "" : "&dimensionY=" . $yDimension); try { //sign URI $signedURI = Utils::sign($strURI); //get response stream $responseStream = Utils::processCommand($signedURI, "GET", "", ""); //Save output barcode image $outputPath = SaasposeApp::$outputLocation . "barcode" . $symbology . "." . $imageFormat; Utils::saveFile($responseStream, $outputPath); return $outputPath; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * convert a particular page to image with default size * @param string $pageNumber * @param string $imageFormat */ public function convertToImage($fileName, $pageNumber, $imageFormat = 'png') { try { $strURI = sprintf("%s/pdf/%s/pages/%s?format=%s", Product::$baseProductUri, $fileName, $pageNumber, $imageFormat); $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { $newFileName = Utils::getFileName($fileName) . "_" . $pageNumber . "." . $imageFormat; Utils::saveFile($responseStream, SaasposeApp::$outputLocation . $newFileName); return $newFileName; } else { throw new Exception($v_output); } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * convert a document to SaveFormat */ public function baseConvert($fileType, $fileName, $saveFormat) { try { $strURI = sprintf("%s/%s/%s?format=%s", Product::$baseProductUri, $fileType, $fileName, $saveFormat); $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { if ($saveFormat == "html") { $saveFormat = "zip"; } $saveFile = SaasposeApp::$outputLocation . Utils::getFileName($fileName) . "." . $saveFormat; Utils::saveFile($responseStream, $saveFile); return $saveFile; } else { throw new Exception($v_output); } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * convert a document to the given saveFormat */ public function convert($fileName, $saveFormat = 'PPT') { try { //check whether file is set or not if ($fileName == "") { throw new Exception("No file name specified"); } $strURI = Product::$baseProductUri . "/slides/" . $fileName . "?format=" . $saveformat; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { Utils::saveFile($responseStream, SaasposeApp::$outputLocation . Utils::getFileName($fileName) . "." . $saveformat); return ""; } else { return $v_output; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Executes mail merge template. * @param string $fileName * @param string $strXML */ public function executeTemplate($strXML) { try { //build URI to execute mail merge template $strURI = Product::$baseProductUri . "/words/" . $this->fileName . "/executeTemplate"; //sign URI $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "POST", "", $strXML); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { $json = json_decode($responseStream); //Save docs on server $folder = new Folder(); $outputStream = $folder->getFile($json->Document->fileName); $outputPath = SaasposeApp::$outputLocation . $this->fileName; Utils::saveFile($outputStream, $outputPath); return ""; } else { return $v_output; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Replace a text with the new value in the document * @param string $fileName * @param string $oldValue * @param string $newValue * @param string $isMatchCase * @param string $isMatchWholeWord */ public function replaceText($fileName, $oldValue, $newValue, $isMatchCase, $isMatchWholeWord) { try { //Build JSON to post $fieldsArray = array('OldValue' => $oldValue, 'NewValue' => $newValue, 'IsMatchCase' => $isMatchCase, 'IsMatchWholeWord' => $isMatchWholeWord); $json = json_encode($fieldsArray); //build URI to replace text $strURI = Product::$baseProductUri . "/words/" . $fileName . "/replaceText"; //sign URI $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "POST", "json", $json); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { //Save docs on server $folder = new Folder(); $outputStream = $folder->getFile($fileName); $outputPath = SaasposeApp::$outputLocation . $fileName; Utils::saveFile($outputStream, $outputPath); return ""; } else { return $v_output; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Split an interval of pages in a self definable format * @param int $from * @param int $to * @param string $format * @throws Exception */ public function splitPagesToAnyFormat($from, $to, $format) { try { if ($this->fileName == "") { throw new Exception("File name not specified"); } $strURI = Product::$baseProductUri . "/pdf/" . $this->fileName . "/split?from=" . $from . "&to=" . $to . "&format=" . $format; $signedURI = Utils::Sign($strURI); $responseStream = Utils::processCommand($signedURI, "POST", "", ""); $json = json_decode($responseStream); $i = 1; $resultFiles = array(); $info = pathinfo($this->fileName); foreach ($json->Result->Documents as $splitPage) { $splitFileName = basename($splitPage->Href); $strURI = Product::$baseProductUri . '/storage/file/' . $splitFileName; $signedURI = Utils::Sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $fileName = $info['filename'] . "_" . $i . "." . $format; $outputFile = SaasposeApp::$outputLocation . $fileName; Utils::saveFile($responseStream, $outputFile); $resultFiles[$i] = $outputFile; $i++; } return $resultFiles; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Gets border of the ChartArea of a chart * $chartIndex */ public function getBorder($chartIndex) { try { $strURI = Product::$baseProductUri . "/cells/" . $this->fileName . "/worksheets/" . $this->worksheetName . "/charts/" . $chartIndex . "/chartArea/border"; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $json = json_decode($responseStream); return $json->Line; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Get pagecount, wordcount, paragraphcount statistics from the Word document * * Example response: * GET http://api.aspose.com/v1.1/words/TestStatDataDocument.doc/statistics * * <?xml version="1.0" encoding="utf-8"?> * <SaaSposeResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> * <Status>OK</Status> * <StatData> * <WordCount>100</WordCount> * <ParagraphCount>40</ParagraphCount> * <PageCount>3</PageCount> * <PageStatData> * <Page number="1"> * <WordCount>25</WordCount> * <ParagraphCount>10</ParagraphCount> * </Page> * <Page number="2"> * <WordCount>45</WordCount> * <ParagraphCount>15</ParagraphCount> * </Page> * <Page number="3"> * <WordCount>30</WordCount> * <ParagraphCount>15</ParagraphCount> * </Page> * </PageStatData> * </StatData> * <DocumentLink href="http://api.aspose.com/v1.1/words/TestStatDataDocument.doc" rel="self" /> * </SaaSposeResponse> * * * @param string $destinationDocumentName * @throws Exception * @return array $json */ public function getStatistics() { //build URI to accept all tracking changes in the document $strUri = Product::$baseProductUri . "/words/" . $this->fileName . "/statistics"; //sign URI $signedUri = Utils::sign($strUri); $responseStream = Utils::processCommand($signedUri, "GET", "json"); $json = json_decode($responseStream); if ($json->Code == 200) { return $json; } else { throw new Exception("Error while retreiving document statistics"); } }
/** * Gets a specific hyperlink from the sheet * $index */ public function getHyperlinkByIndex($index) { try { $strURI = Product::$baseProductUri . "/cells/" . $this->fileName . "/worksheets/" . $this->worksheetName . "/hyperlinks/" . $index; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $json = json_decode($responseStream); return $json->Hyperlink; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Saves a particular slide into various formats * @param number $slideNumber * @param string $outputPath * @param string $saveFormat */ public function saveSlideAs($slideNumber = "", $outputPath = "", $saveFormat = "") { try { if ($outputPath == "") { throw new Exception("Output path not specified"); } if ($saveFormat == "") { throw new Exception("Save format not specified"); } if ($slideNumber == "") { throw new Exception("Slide number not specified"); } $strURI = Product::$baseProductUri . "/slides/" . $this->fileName . "/slides/{$slideNumber}?format=" . $saveFormat; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { Utils::saveFile($responseStream, $outputPath . Utils::getFileName($this->fileName) . "." . $saveFormat); return true; } else { return $v_output; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Gets a placeholder from a particular slide * $slideNumber * $placeholderIndex */ public function getPlaceholder($slideNumber, $placeholderIndex) { try { $strURI = Product::$baseProductUri . "/slides/" . $this->fileName . "/slides/" . $slideNumber . "/placeholders/" . $placeholderIndex; //Build URI to get placeholders $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $json = json_decode($responseStream); return $json->Placeholder; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Replaces all instances of old text with new text in a PDF file or a particular page * @param string $oldText * @param string $newText */ public function replaceText($oldText, $newText, $isRegularExpression, $pageNumber = null) { try { //Build JSON to post $fieldsArray = array('OldValue' => $oldText, 'NewValue' => $newText, 'Regex' => $isRegularExpression); $json = json_encode($fieldsArray); //Build URI to replace text $strURI = sprintf("%s/slides/%s%s/replaceText", Product::$baseProductUri, $this->fileName, !is_null($pageNumber) ? "/pages/" . $pageNumber : ""); $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "POST", "json", $json); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { //Save doc on server $folder = new Folder(); $outputStream = $folder->getFile($this->fileName); $outputPath = SaasposeApp::$outputLocation . $this->fileName; Utils::saveFile($outputStream, $outputPath); return ""; } else { return $v_output; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Deletes all slides from a presentation */ public function deleteAllSlides() { try { //Build URI to replace text $strURI = Product::$baseProductUri . "/slides/" . $this->fileName . "/slides"; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "DELETE", "", ""); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { //Save doc on server $folder = new Folder(); $outputStream = $folder->getFile($this->fileName); $outputPath = SaasposeApp::$outputLocation . $this->fileName; Utils::saveFile($outputStream, $outputPath); return ""; } else { return $v_output; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Gets a specfied link on a specified document page * @param $pageNumber * @param $linkIndex */ public function getLink($pageNumber, $linkIndex) { try { //check whether file is set or not if ($this->fileName == "") { throw new Exception("No file name specified"); } $strURI = Product::$baseProductUri . "/pdf/" . $this->fileName . "/pages/" . $pageNumber . "/links/" . $linkIndex; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $json = json_decode($responseStream); return $json->Link; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Get the List of drawing object from document * @param string outputPath */ public function getDrawingObjects($outputPath = "") { try { if ($outputPath == "") { throw new Exception("Output path not specified"); } $strURI = Product::$baseProductUri . "/words/" . $this->fileName . "/drawingObjects"; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $json = json_decode($responseStream); if ($json->Code == 200) { foreach ($json->DrawingObjects->List as $object) { $this->getDrawingObject($object->link->Href, $outputPath); } } else { return false; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * saves a specific auto-shape from a specific sheet as image * @param $worksheetName * @param $shapeIndex * @param $imageFormat */ public function getAutoShape($worksheetName, $shapeIndex, $imageFormat) { try { //Build URI $strURI = Product::$baseProductUri . "/cells/" . $this->fileName . "/worksheets/" . $worksheetName . "/autoshapes/" . $shapeIndex . "?format=" . $imageFormat; //sign URI $signedURI = Utils::sign($strURI); //Send request and receive response stream $responseStream = Utils::processCommand($signedURI, "GET", "", ""); //Validate output $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { //Save ouput file $outputPath = SaasposeApp::$outputLocation . Utils::getFileName($this->fileName) . "_" . $worksheetName . "." . $imageFormat; Utils::saveFile($responseStream, $outputPath); return ""; } else { return $v_output; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Retrieves the list of files and folders under the specified folder. Use empty string to specify root folder. * * @param string $strFolder */ public function getFilesList($strFolder) { try { //build URI $strURI = $this->strURIFolder; //check whether file is set or not if (!$strFolder == "") { $strURI .= $strFolder; } //sign URI $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $json = json_decode($responseStream); return $json->Files; } catch (Exception $e) { throw new Exception($e->getMessage()); } }