/** * 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()); } }
/** * 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()); } }
/** * 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()); } }
/** * Deletes a chart * $chartIndex */ public function deleteChart($chartIndex) { try { $strURI = Product::$baseProductUri . "/cells/" . $this->fileName . "/worksheets/" . $this->worksheetName . "/charts/" . $chartIndex; $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()); } }
/** * 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()); } }
/** * 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()); } }
/** * Download the selected attachment from Pdf document * @param string $attachmentIndex */ public function downloadAttachment($attachmentIndex) { try { //check whether files are set or not if ($this->fileName == "") { throw new Exception("PDF file name not specified"); } $fileInformation = $this->getAttachment($attachmentIndex); //build URI to download attachment $strURI = Product::$baseProductUri . "/pdf/" . $this->fileName . "/attachments/" . $attachmentIndex . "/download"; //sign URI $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { Utils::saveFile($responseStream, SaasposeApp::$outputLocation . $fileInformation->Name); return ""; } else { return $v_output; } } 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()); } }
/** * 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()); } }
/** * Convert Document to different file format without using storage * $param string $inputPath * @param string $outputPath * @param string $outputFormat */ public function convertLocalFile($inputPath = "", $outputPath = "", $outputFormat = "") { try { //check whether file is set or not if ($inputPath == "") { throw new Exception("No file name specified"); } if ($outputFormat == "") { throw new Exception("output format not specified"); } $strURI = Product::$baseProductUri . "/words/convert?format=" . $outputFormat; if (!file_exists($inputPath)) { throw new Exception("input file doesn't exist."); } $signedURI = Utils::sign($strURI); $responseStream = Utils::uploadFileBinary($signedURI, $inputPath, "xml"); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { if ($outputFormat == "html") { $save_format = "zip"; } else { $save_format = $outputFormat; } if ($outputPath == "") { $outputPath = Utils::getFileName($inputPath) . "." . $save_format; } Utils::saveFile($responseStream, SaasposeApp::$outputLocation . $outputPath); return true; } else { return $v_output; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * Get the drawing object from document * @param string $objectURI * @param string $outputPath */ public function getDrawingObject($objectURI = "", $outputPath = "") { try { if ($outputPath == "") { throw new Exception("Output path not specified"); } if ($objectURI == "") { throw new Exception("Object URI not specified"); } $url_arr = explode("/", $objectURI); $objectIndex = end($url_arr); $strURI = $objectURI; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $json = json_decode($responseStream); if ($json->Code == 200) { if ($json->DrawingObject->ImageDataLink != "") { $strURI = $strURI . "/imageData"; $outputPath = $outputPath . "\\DrawingObject_" . $objectIndex . ".jpeg"; } else { if ($json->DrawingObject->OLEDataLink != "") { $strURI = $strURI . "/oleData"; $outputPath = $outputPath . "\\DrawingObject_" . $objectIndex . ".xlsx"; } else { $strURI = $strURI . "?format=jpeg"; $outputPath = $outputPath . "\\DrawingObject_" . $objectIndex . ".jpeg"; } } $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { Utils::saveFile($responseStream, $outputPath); return true; } else { return $v_output; } } else { return false; } } 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()); } }
/** * 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()); } }
/** * 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()); } }
/** * 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()); } }