/** * Appends a list of documents to this one. * @param string $appendDocs (List of documents to append) * @param string $importFormatModes * @param string $sourceFolder (name of the folder where documents are present) */ public function appendDocument($appendDocs, $importFormatModes, $sourceFolder) { try { //check whether required information is complete if (count($appendDocs) != count($importFormatModes)) { throw new Exception("Please specify complete documents and import format modes"); } //Build JSON to post $json = '{ "DocumentEntries": ['; for ($i = 0; $i < count($appendDocs); $i++) { $json .= '{ "Href": "' . $sourceFolder . $appendDocs[$i] . '", "ImportFormatMode": "' . $importFormatModes[$i] . '" }' . ($i < count($appendDocs) - 1 ? ',' : ''); } $json .= ' ] }'; //build URI to merge Docs $strURI = Product::$baseProductUri . "/words/" . $this->fileName . "/appendDocument"; //sign URI $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "POST", "json", $json); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { //Save merged docs on server $folder = new Folder(); $outputStream = $folder->getFile($sourceFolder . ($sourceFolder == '' ? '' : '/') . $this->fileName); $outputPath = SaasposeApp::$outputLocation . $this->fileName; Utils::saveFile($outputStream, $outputPath); 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()); } }
/** * Replaces Image in PDF File using Local Image Stream * $pageNumber * $imageIndex * $fileName */ public function replaceImageUsingFile($pageNumber, $imageIndex, $fileName) { try { //check whether files are set or not if ($this->fileName == "") { throw new Exception("PDF file name not specified"); } //build URI to replace image $strURI = Product::$baseProductUri . "/pdf/" . $this->fileName . "/pages/" . $pageNumber . "/images/" . $imageIndex . "?imageFile=" . $fileName; //sign URI $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, "POST", "", ""); $v_output = Utils::validateOutput($responseStream); if ($v_output === "") { //Save PDF file 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()); } }