/**
  * Convert Image Format.
  *
  * @param string $inputPath Input file path.
  * @param string $outputFormat Output file format.
  *
  * @return string Returns the file path.
  * @throws Exception
  */
 public function convertLocalFile($inputPath, $outputFormat)
 {
     //check whether files are set or not
     if ($inputPath == '') {
         throw new Exception('Input file not specified');
     }
     if ($outputFormat == '') {
         throw new Exception('Format not specified');
     }
     //build URI
     $strURI = Product::$baseProductUri . '/imaging/' . $this->getFileName() . '/saveAs?format=' . $outputFormat;
     //sign URI
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::uploadFileBinary($signedURI, $inputPath, 'xml', 'POST');
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output === '') {
         if ($outputFormat == 'html') {
             $saveFormat = 'zip';
         } else {
             $saveFormat = $outputFormat;
         }
         $outputFilename = Utils::getFileName($inputPath) . '.' . $saveFormat;
         Utils::saveFile($responseStream, AsposeApp::$outPutLocation . $outputFilename);
         return $outputFilename;
     } else {
         return $v_output;
     }
 }
 /**
  * Generates new barcodes with specific text, symbology, image format,
  * resolution and dimensions.
  *
  * @param string $codeText Text to encode inside barcode.
  * @param string $symbology Type of barcode.
  * @param string $imageFormat Returns an image in the specified format.
  * @param float $xResolution Resolution along X in dpi.
  * @param float $yResolution Resolution along Y in dpi.
  * @param float $xDimension Width of barcode unit (bar or space).
  * @param float $yDimension Height of barcode unit (for 2D barcodes).
  *
  * @return string Returns the file path.
  * @throws Exception
  */
 public function save($codeText, $symbology, $imageFormat = 'png', $xResolution = 0, $yResolution = 0, $xDimension = 0, $yDimension = 0, $codeLocation = null, $folder = null, $storage = null, $name = null, $grUnit = null, $autoSize = null, $barHeight = 0, $imageHeight = 0, $imageWidth = 0, $imageQuality = null, $rotAngle = 0, $topMargin = 0, $bottomMargin = 0, $leftMargin = 0, $rightMargin = 0, $enableChecksum = null)
 {
     //build URI to generate barcode
     $strURI = Product::$baseProductUri . '/barcode' . (strlen($name) <= 0 ? '' : '/' . $name) . '/generate?text=' . $codeText . '&type=' . $symbology . '&format=' . $imageFormat . ($xResolution <= 0 ? '' : '&resolutionX=' . $xResolution) . ($yResolution <= 0 ? '' : '&resolutionY=' . $yResolution) . ($xDimension <= 0 ? '' : '&dimensionX=' . $xDimension) . ($yDimension <= 0 ? '' : '&dimensionY=' . $yDimension) . (strlen($codeLocation) <= 0 ? '' : '&codeLocation=' . $codeLocation) . (strlen($grUnit) <= 0 ? '' : '&grUnit=' . $grUnit) . (strlen($autoSize) <= 0 ? '' : '&autoSize=' . $autoSize) . ($barHeight <= 0 ? '' : '&barHeight=' . $barHeight) . ($imageHeight <= 0 ? '' : '&imageHeight=' . $imageHeight) . ($imageWidth <= 0 ? '' : '&imageWidth=' . $imageWidth) . (strlen($imageQuality) <= 0 ? '' : '&imageQuality=' . $imageQuality) . ($rotAngle <= 0 ? '' : '&rotAngle=' . $rotAngle) . ($topMargin <= 0 ? '' : '&topMargin=' . $topMargin) . ($bottomMargin <= 0 ? '' : '&bottomMargin=' . $bottomMargin) . ($leftMargin <= 0 ? '' : '&leftMargin=' . $leftMargin) . ($rightMargin <= 0 ? '' : '&rightMargin=' . $rightMargin) . (strlen($folder) <= 0 ? '' : '&folder=' . $folder) . (strlen($storage) <= 0 ? '' : '&storage=' . $storage) . (strlen($enableChecksum) <= 0 ? '' : '&enableChecksum=' . $enableChecksum);
     if (strlen($codeLocation) <= 0 and strlen($grUnit) <= 0 and strlen($autoSize) <= 0 and $barHeight <= 0 and $imageHeight <= 0 and $imageWidth <= 0 and strlen($imageQuality) <= 0 and $rotAngle <= 0 and $topMargin <= 0 and $bottomMargin <= 0 and $leftMargin <= 0 and $rightMargin <= 0 and strlen($folder) <= 0 and strlen($storage) <= 0 and strlen($name) <= 0 and strlen($enableChecksum) <= 0) {
         //sign URI
         $signedURI = Utils::sign($strURI);
         //get response stream
         $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
         //Save output barcode image
         $outputPath = AsposeApp::$outPutLocation . 'barcode' . $symbology . '.' . $imageFormat;
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     } else {
         //sign URI
         $signedURI = Utils::sign($strURI);
         //get response stream
         $responseStream = Utils::processCommand($signedURI, 'PUT', '', '');
         //build URI to execute mail merge
         $strURI = 'http://api.aspose.com/v1.0/storage/file/' . $name;
         //sign URI
         $signedURI = Utils::sign($strURI);
         //get response stream
         $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
         //Save output barcode image
         $outputPath = AsposeApp::$outPutLocation . 'barcode' . $symbology . '.' . $imageFormat;
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     }
 }
 /**
  * Gets all merge filed names from document.
  *
  * @param string $fileName The name of source file.
  *
  * @return array
  * @throws Exception
  */
 public function getMailMergeFieldNames($fileName)
 {
     //check whether file is set or not
     if ($fileName == '') {
         throw new Exception('No file name specified');
     }
     $strURI = Product::$baseProductUri . '/words/' . $fileName . '/mailMergeFieldNames';
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
     $json = json_decode($responseStream);
     return $json->FieldNames->Names;
 }
 /**
  * Get the particular image from the specified page with the default image size.
  *
  * @param int $pageNumber Number of the page.
  * @param int $imageIndex Index of the page.
  * @param string $imageFormat Returns image in the specified format.
  * @param int $imageWidth Width of the image.
  * @param int $imageHeight Height of the image.
  *
  * @return string Returns the file path.
  * @throws Exception
  */
 public function getImageCustomSize($pageNumber, $imageIndex, $imageFormat, $imageWidth, $imageHeight)
 {
     $strURI = Product::$baseProductUri . '/pdf/' . $this->getFileName() . '/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 === '') {
         $outputPath = AsposeApp::$outPutLocation . Utils::getFileName($this->getFileName()) . '_' . $imageIndex . '.' . $imageFormat;
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 /**
  * Convert a document to SaveFormat using Aspose storage.
  *
  * @return string Returns the file path.
  * @throws Exception
  */
 public function convert()
 {
     //build URI
     $strURI = Product::$baseProductUri . '/tasks/' . $this->getFileName() . '?format=' . $this->saveFormat;
     //sign URI
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output === '') {
         if ($this->saveFormat == 'html') {
             $save_format = 'zip';
         } else {
             $save_format = $this->saveFormat;
         }
         $outputPath = AsposeApp::$outPutLocation . Utils::getFileName($this->getFileName()) . '.' . $save_format;
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 /**
  * Copies a file in Aspose storage to a new destination
  *
  * @param string $fileName The name of file.
  * @param string $storageName The name of storage.
  * @return bool
  * @throws Exception
  */
 public function copyFile($fileName, $storageName = '', $newDest)
 {
     //check whether file is set or not
     if ($fileName == '' || $newDest == '') {
         AsposeApp::getLogger()->error(Exception::MSG_NO_FILENAME);
         throw new Exception(Exception::MSG_NO_FILENAME);
     }
     //build URI
     $strURI = $this->strURIFile . $fileName . '?newdest=' . $newDest;
     if ($storageName != '') {
         $strURI .= '&storage=' . $storageName;
     }
     //sign URI
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'PUT', '', '');
     $json = json_decode($responseStream);
     if ($json->Code === 200) {
         return true;
     }
     return false;
 }
 /**
  * Deletes a project assignment with all references to it.
  *
  * @param integer $assignmentUid The uid of assignment.
  * @param string $changedFileName The name of the project document to save changes to. If this parameter is omitted then the changes will be saved to the source project document.
  *
  * @return string Returns the assignment path.
  * @throws Exception
  */
 public function deleteAssignment($assignmentUid, $changedFileName)
 {
     if ($assignmentUid == '') {
         throw new Exception('Assignment Uid not specified');
     }
     //build URI
     $strURI = Product::$baseProductUri . '/tasks/' . $this->getFileName() . '/assignments/' . $assignmentUid;
     if ($changedFileName != '') {
         $strURI .= '?fileName=' . $changedFileName;
         $this->setFileName($changedFileName);
     }
     //sign URI
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'DELETE', '', '');
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output === '') {
         $folder = new Folder();
         $outputStream = $folder->GetFile($this->getFileName());
         $outputPath = AsposeApp::$outPutLocation . $this->getFileName();
         Utils::saveFile($outputStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 /**
  * Sign PDF Documents
  *
  * @param int|string $pageNumber Number of the page.
  * @param json $postData Data should be in JSON format.
  * @return bool|string
  * @throws Exception
  */
 public function addSignature($pageNumber = '', $postData)
 {
     if ($postData == '') {
         throw new Exception('Data not provided');
     }
     $strURI = Product::$baseProductUri . '/pdf/' . $this->getFileName();
     if ($pageNumber) {
         $strURI .= '/pages/' . $pageNumber;
     }
     $strURI .= '/sign';
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'POST', 'JSON', $postData);
     $json = json_decode($responseStream);
     if ($json->Code == 200) {
         $folder = new Folder();
         $outputStream = $folder->GetFile($this->getFileName());
         $outputPath = AsposeApp::$outPutLocation . $this->getFileName();
         Utils::saveFile($outputStream, $outputPath);
         return $outputPath;
     } else {
         return false;
     }
 }
 /**
  * Update PSD Image Properties without storage.
  *
  * @param integer $channelsCount Count of channels.
  * @param string $compression Compression method.
  * @param string $outPath Name of the output file.
  *
  * @return string Returns the file path.
  * @throws Exception
  */
 public function updatePSDPropertiesFromLocalFile($inputPath, $channelsCount, $compression, $outPath)
 {
     if ($channelsCount == '') {
         throw new Exception('Channels count not specified');
     }
     if ($compression == '') {
         throw new Exception('Compression method not specified');
     }
     if ($outPath == '') {
         throw new Exception('Output file name not specified');
     }
     //build URI
     $strURI = Product::$baseProductUri . '/imaging/psd?channelsCount=' . $channelsCount . '&compression=' . $compression . '&outPath=' . $outPath;
     //sign URI
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::uploadFileBinary($signedURI, $inputPath, 'xml', 'POST');
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output === '') {
         $folder = new Folder();
         $outputStream = $folder->GetFile($outPath);
         $outputPath = AsposeApp::$outPutLocation . $outPath;
         Utils::saveFile($outputStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 public function getFilesList($strFolder, $storageName = '')
 {
     //build URI
     $strURI = $this->strURIFolder;
     //check whether file is set or not
     if (!$strFolder == '') {
         $strURI .= $strFolder;
     }
     if ($storageName != '') {
         $strURI .= '?storage=' . $storageName;
     }
     //sign URI
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
     $json = json_decode($responseStream);
     return $json->Files;
 }
 /**
  * Get Aspect Ratio of a PowerPoint Slide
  * 
  * @param type $slideNumber The number of slide.
  * 
  * @return float|boolean
  * @throws Exception
  */
 public function aspectRatio($slideNumber)
 {
     if ($slideNumber == '') {
         throw new Exception('Slide number not specified');
     }
     //build URI
     $strURI = Product::$baseProductUri . '/slides/' . $this->getFileName() . '/slides/' . $slideNumber;
     //sign URI
     $signedURI = Utils::sign($strURI);
     $response = Utils::processCommand($signedURI, 'GET', '', '');
     $json = json_decode($response);
     if ($json->Code == 200) {
         return $json->Slide->Width / $json->Slide->Height;
     } else {
         return false;
     }
 }
 /**
  * Convert Excel Workbook with Additional Settings
  * 
  * @param xml $strXML Data in XML format.
  * @param string $outputFile The name of output file.
  * 
  * @return string Returns the file path.
  * @throws Exception
  */
 public function saveAs($strXML, $outputFile)
 {
     if ($strXML == '') {
         throw new Exception('XML Data not specified');
     }
     if ($outputFile == '') {
         throw new Exception('Output Filename along extension not specified');
     }
     $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() . '/saveAs?newfilename=' . $outputFile;
     $signedURI = Utils::Sign($strURI);
     $responseStream = Utils::processCommand($signedURI, "POST", "XML", $strXML);
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output === '') {
         $strURI = Product::$baseProductUri . '/storage/file/' . $outputFile;
         $signedURI = Utils::Sign($strURI);
         $responseStream = Utils::processCommand($signedURI, "GET", "", "");
         $outputPath = AsposeApp::$outPutLocation . $outputFile;
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 public static function getAjax()
 {
     $module_path = dirname(__FILE__);
     JLoader::registerNamespace('Aspose', $module_path . '/Aspose_Cloud_SDK_For_PHP-master/src');
     $jAp = JFactory::getApplication();
     $myJoomlaInput = $jAp->input;
     // Get Module Configurations
     $module_params = static::getParams();
     // Set Application ID and Application Key for Aspose SDK
     $app_id = $module_params->get('pdf_importer_app_sid', false);
     $app_key = $module_params->get('pdf_importer_app_key', false);
     $aspose_pdf_importer_option = $module_params->get('aspose_pdf_importer_option', false);
     if (!$app_id || !$app_key || empty($app_id) || empty($app_key)) {
         die("APP Id/ APP Key for Aspose SDK not found");
     }
     \Aspose\Cloud\Common\AsposeApp::$appSID = $app_id;
     \Aspose\Cloud\Common\AsposeApp::$appKey = $app_key;
     /*
      * Assign Base Product URL
      */
     \Aspose\Cloud\Common\Product::$baseProductUri = 'http://api.aspose.com/v1.1';
     $uploadpath = JPATH_ADMINISTRATOR . "/" . "modules" . "/" . "mod_aspose_pdf_importer" . "/" . "uploads/";
     \Aspose\Cloud\Common\AsposeApp::$outPutLocation = $uploadpath;
     $file_received = $myJoomlaInput->files->get('filePath');
     if (is_array($file_received) && count($file_received) > 0) {
         jimport('joomla.filesystem.file');
         //Clean up filename to get rid of strange characters like spaces etc
         $uploadfilename = time() . '_' . JFile::makeSafe($file_received['name']);
         //Set up the source and destination of the file
         $src = $file_received['tmp_name'];
         $dest = JPATH_ADMINISTRATOR . "/" . "modules" . "/" . "mod_aspose_pdf_importer" . "/" . "uploads" . "/" . $uploadfilename;
         //First check if the file has the right extension, we need pdf only
         if (strtolower(JFile::getExt($uploadfilename)) == 'pdf') {
             if (JFile::upload($src, $dest)) {
                 $folder = new \Aspose\Cloud\Storage\Folder();
                 $uploadpath = str_replace("\\", "/", $dest);
                 $uploadFile = $dest;
                 $folder->uploadFile($uploadFile, '');
             } else {
                 die("There is some problem in uploading File.");
             }
         } else {
             die("Wrong File was selected!");
         }
     }
     if (isset($_REQUEST['filename']) && !empty($_REQUEST['filename'])) {
         $filename = $_REQUEST['filename'];
     } else {
         $filename = $uploadfilename;
     }
     $ext = pathinfo($filename, PATHINFO_EXTENSION);
     $ext = strtolower($ext);
     if ($ext == 'pdf') {
         \Aspose\Cloud\Common\AsposeApp::$outPutLocation = $uploadpath;
         // 'F:\\xampp\htdocs\\wordpress\\uploads\\';
         $filename = trim($filename);
         if ($aspose_pdf_importer_option == 'html') {
             $converter = new \Aspose\Cloud\Pdf\Converter($filename);
             $converter->saveFormat = 'html';
             $converter->fileName = $filename;
             $saved_file = $converter->convert();
             $targetdir_arr = pathinfo($saved_file);
             ModAsposePdfImporterHelper::unzip($targetdir_arr['dirname'] . '/' . str_replace('.zip', '', $targetdir_arr['basename']), $targetdir_arr['dirname'] . '/' . $targetdir_arr['basename']);
             $file_name = $targetdir_arr['dirname'] . '/' . str_replace('.zip', '', $targetdir_arr['basename']) . '/' . \Aspose\Cloud\Common\Utils::getFileName($filename) . '.html';
             $file_name = str_replace("\\", "/", $file_name);
             $file_html = file_get_contents($file_name);
             $file_html_folder = \Aspose\Cloud\Common\Utils::getFileName($filename) . '_files';
             $destination = JURI::base() . "modules" . "/" . "mod_aspose_pdf_importer" . "/" . "uploads/";
             $file_html = str_replace($file_html_folder, $destination . '/' . \Aspose\Cloud\Common\Utils::getFileName($filename) . '/' . $file_html_folder, $file_html);
             $css_file = @file_get_contents($uploadpath . '/' . \Aspose\Cloud\Common\Utils::getFileName($filename) . '/' . $file_html_folder . '/style.css');
             $css_array = ModAsposePdfImporterHelper::parse($css_file);
             preg_match_all('/class="([^"]+)"/i', $file_html, $matches);
             foreach ($matches[1] as $key => $class_name) {
                 $classes_arr = explode(' ', $class_name);
                 $style_text = '';
                 if (is_array($classes_arr) && count($classes_arr) > 0) {
                     foreach ($classes_arr as $c) {
                         $key_index = @$css_array['.' . $c];
                         if (@is_array($css_array['.' . $c])) {
                             foreach ($css_array['.' . $c] as $style_key => $style_value) {
                                 if ($style_key != '' && $style_value != '' && $style_key != 'font-family') {
                                     $style_text .= $style_key . ':' . $style_value . ';';
                                 }
                             }
                         }
                     }
                 }
                 if ($style_text != '') {
                     $replace_string = 'style="' . $style_text . '"';
                     $c_n = 'class="' . $class_name . '"';
                     $file_html = str_replace($c_n, $replace_string, $file_html);
                 }
             }
             preg_match_all('/style="([^"]+)" style="([^"]+)"/', $file_html, $match_arr);
             foreach ($match_arr['0'] as $key => $m) {
                 $file_html = str_replace($m, 'style="' . $match_arr['1'][$key] . $match_arr['2'][$key] . '"', $file_html);
             }
             $content = $file_html;
         } else {
             $func = new \Aspose\Cloud\Pdf\TextEditor($filename);
             $output = $func->getText();
             $output_arr = explode('.', $output);
             $content = '';
             foreach ($output_arr as $output) {
                 $content .= '<p>' . $output . '</p>';
             }
         }
         die($content);
     } else {
         die("Wrong File was selected!");
     }
 }
 /**
  * Convert PowerPoint Documents to other File Formats with Additional Settings
  * 
  * @param type $saveFormat Return the presentation in the specified format. 
  * @param type $textCompression Specifies compression type to be used for all textual content in the document. 
  * @param type $embedFullFonts Determines if all characters of font should be embedded or only used subset. 
  * @param type $compliance Desired conformance level for generated PDF document.
  * @param type $jpegQuality Value determining the quality of the JPEG images inside PDF document. 
  * @param type $saveMetafilesAsPng True to convert all metafiles used in a presentation to the PNG images. 
  * @param type $pdfPassword Setting user password to protect the PDF document. 
  * @param type $embedTrueTypeFontsForASCII Determines service will embed common fonts for ASCII.
  * 
  * @return string Returns the file path.
  */
 public function convertWithAdditionalSettings($saveFormat = 'pdf', $textCompression = '', $embedFullFonts = '', $compliance = '', $jpegQuality = '', $saveMetafilesAsPng = '', $pdfPassword = '', $embedTrueTypeFontsForASCII = '')
 {
     $strURI = Product::$baseProductUri . '/slides/' . $this->getFileName() . '?format=' . $saveFormat;
     if ($textCompression != '') {
         $strURI .= '&TextCompression=' . $textCompression;
     }
     if ($embedFullFonts != '') {
         $strURI .= '&EmbedFullFonts=' . $embedFullFonts;
     }
     if ($compliance != '') {
         $strURI .= '&Compliance=' . $compliance;
     }
     if ($jpegQuality != '') {
         $strURI .= '&JpegQuality=' . $jpegQuality;
     }
     if ($saveMetafilesAsPng != '') {
         $strURI .= '&SaveMetafilesAsPng=' . $saveMetafilesAsPng;
     }
     if ($pdfPassword != '') {
         $strURI .= '&PdfPassword='******'') {
         $strURI .= '&EmbedTrueTypeFontsForASCII=' . $embedTrueTypeFontsForASCII;
     }
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output === '') {
         $outputPath = AsposeApp::$outPutLocation . Utils::getFileName($this->getFileName()) . '.' . $saveFormat;
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 /**
  * Manipulate a Frame and Save the Modified Frame Along with Unmodified Frames.
  *
  * @param integer $frameId Number of frame.
  * @param string $rotateFlipMethod RotateFlip method.
  * @param integer $newWidth New width of the scaled image.
  * @param integer $newHeight New height of the scaled image.
  * @param integer $x X position of start point for cropping rectangle.
  * @param integer $y Y position of start point for cropping rectangle.
  * @param integer $rectWidth Width of cropping rectangle.
  * @param integer $rectHeight Height of cropping rectangle.
  * @param string $outPath Path to updated file.
  *
  * @return string Returns the file path.
  * @throws Exception
  */
 public function manipulateFrame($frameId, $rotateFlipMethod, $newWidth, $newHeight, $x, $y, $rectWidth, $rectHeight, $outPath)
 {
     if ($frameId == '') {
         throw new Exception('Frame ID not specified');
     }
     if ($rotateFlipMethod == '') {
         throw new Exception('RotateFlip method not specified');
     }
     if ($newWidth == '') {
         throw new Exception('New width not specified');
     }
     if ($newHeight == '') {
         throw new Exception('New height not specified');
     }
     if ($x == '') {
         throw new Exception('X position not specified');
     }
     if ($y == '') {
         throw new Exception('Y position not specified');
     }
     if ($rectWidth == '') {
         throw new Exception('Width of cropping rectangle not specified');
     }
     if ($rectHeight == '') {
         throw new Exception('Height of cropping rectangle not specified');
     }
     if ($outPath == '') {
         throw new Exception('Output file not specified');
     }
     //build URI
     $strURI = Product::$baseProductUri . '/imaging/' . $this->getFileName() . '/frames/' . $frameId . '?saveOtherFrames=false&rotateFlipMethod=' . $rotateFlipMethod . '&newWidth=' . $newWidth . '&newHeight=' . $newHeight . '&x=' . $x . '&y=' . $y . '&rectWidth=' . $rectWidth . '&rectHeight=' . $rectHeight . '&outPath=' . $outPath;
     //sign URI
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output === '') {
         $folder = new Folder();
         $outputStream = $folder->GetFile($outPath);
         $outputPath = AsposeApp::$outPutLocation . $outPath;
         Utils::saveFile($outputStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 public function replaceText()
 {
     $parameters = func_get_args();
     //set parameter values
     if (count($parameters) == 3) {
         $oldText = $parameters[0];
         $newText = $parameters[1];
         $isRegularExpression = $parameters[2];
     } else {
         if (count($parameters) == 4) {
             $oldText = $parameters[0];
             $newText = $parameters[1];
             $isRegularExpression = $parameters[2];
             $pageNumber = $parameters[3];
         } else {
             throw new Exception('Invalid number of arguments');
         }
     }
     //check whether file is set or not
     if ($this->fileName == '') {
         throw new Exception('No file name specified');
     }
     //Build JSON to post
     $fieldsArray = array('OldValue' => $oldText, 'NewValue' => $newText, 'Regex' => $isRegularExpression);
     $json = json_encode($fieldsArray);
     //Build URI to replace text
     $strURI = Product::$baseProductUri . '/pdf/' . $this->fileName . (isset($parameters[3]) ? '/pages/' . $pageNumber : '') . '/replaceText';
     $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 = AsposeApp::$outPutLocation . $this->fileName;
         Utils::saveFile($outputStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 /**
  * Add email attachment.
  *
  * @param string $attachmentName The name of attached file.
  *
  * @return string Return path of the attached file.
  * @throws Exception
  */
 public function addAttachment($attachmentName)
 {
     if ($attachmentName == '') {
         throw new Exception('Attachment Name not specified');
     }
     //build URI
     $strURI = Product::$baseProductUri . '/email/' . $this->getFileName() . '/attachments/' . $attachmentName;
     //sign URI
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'POST', '', '');
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output === '') {
         $strURI = Product::$baseProductUri . '/storage/file/' . $this->getFileName();
         $signedURI = Utils::Sign($strURI);
         $responseStream = Utils::processCommand($signedURI, "GET", "", "");
         $outputPath = AsposeApp::$outPutLocation . $this->getFileName();
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 /**
  * Convert file into specified format without using Aspose cloud storage.
  * @param string $inputFile Path of the source file.
  * @param string $outputFile Name of the output file.
  * @param string $saveFormat Returns document in the specified format.
  *
  * @return string Returns the file path.
  * @throws Exception
  */
 public function convertLocalFile($inputFile, $outputFile, $saveFormat)
 {
     if ($inputFile == '') {
         throw new Exception('Please Specify Input File Name along with path');
     }
     if ($outputFile == '') {
         throw new Exception('Please Specify Output File Name along with Extension');
     }
     if ($saveFormat == '') {
         throw new Exception('Please Specify a Save Format');
     }
     $strURI = Product::$baseProductUri . '/cells/convert?format=' . $saveFormat;
     $signedURI = Utils::sign($strURI);
     if (!file_exists($inputFile)) {
         throw new Exception('Input File Doesnt Exists');
     }
     $responseStream = Utils::uploadFileBinary($signedURI, $inputFile, 'xml');
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output === '') {
         if ($saveFormat == 'html') {
             $outputFormat = 'zip';
         } else {
             $outputFormat = $saveFormat;
         }
         if ($outputFile == '') {
             $outputFileName = Utils::getFileName($inputFile) . '.' . $outputFormat;
         } else {
             $outputFileName = Utils::getFileName($outputFile) . '.' . $outputFormat;
         }
         Utils::saveFile($responseStream, AsposeApp::$outPutLocation . $outputFileName);
         return $outputFileName;
     } else {
         return $v_output;
     }
 }
 /**
  * Delete Chart Title in Excel Worksheet
  *
  * @param integer $chartIndex Index of the chart.
  *
  * @return boolean
  * @throws Exception
  */
 public function deleteChartTitle($chartIndex)
 {
     //check whether workshett name is set or not
     if ($this->worksheetName == '') {
         throw new Exception('Worksheet name not specified');
     }
     if (!isset($chartIndex)) {
         throw new Exception('Chart Index not specified');
     }
     $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() . '/worksheets/' . $this->worksheetName . '/charts/' . $chartIndex . '/title';
     $signedURI = Utils::sign($strURI);
     $response = Utils::processCommand($signedURI, 'DELETE', '', '');
     $json = json_decode($response);
     if ($json->Code == 200) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Perform Several Operations on Image
  * 
  * @param string $rotateFlipMethod RotateFlip method.
  * @param integer $newWidth New width of the scaled image.
  * @param integer $newHeight New height of the scaled image.
  * @param integer $xPosition X position of start point for cropping rectangle.
  * @param integer $yPosition Y position of start point for cropping rectangle.
  * @param integer $rectWidth Width of cropping rectangle.
  * @param integer $rectHeight Height of cropping rectangle.
  * @param string $saveFormat Save image in another format.
  * @param string $outPath Path to updated file.
  * 
  * @return boolean|string
  * @throws Exception
  */
 public function updateImage($rotateFlipMethod, $newWidth, $newHeight, $xPosition, $yPosition, $rectWidth, $rectHeight, $saveFormat, $outPath)
 {
     if ($rotateFlipMethod == '') {
         throw new Exception('Rotate Flip Method not specified');
     }
     if ($newWidth == '') {
         throw new Exception('New width not specified');
     }
     if ($newHeight == '') {
         throw new Exception('New Height not specified');
     }
     if ($xPosition == '') {
         throw new Exception('X position not specified');
     }
     if ($yPosition == '') {
         throw new Exception('Y position not specified');
     }
     if ($rectWidth == '') {
         throw new Exception('Rectangle width not specified');
     }
     if ($rectHeight == '') {
         throw new Exception('Rectangle Height not specified');
     }
     if ($saveFormat == '') {
         throw new Exception('Format not specified');
     }
     if ($outPath == '') {
         throw new Exception('Output file name not specified');
     }
     //build URI
     $strURI = Product::$baseProductUri . '/imaging/' . $this->getFileName() . '/updateimage?rotateFlipMethod=' . $rotateFlipMethod . '&newWidth=' . $newWidth . '&newHeight=' . $newHeight . '&x=' . $xPosition . '&y=' . $yPosition . '&rectWidth=' . $rectWidth . '&rectHeight=' . $rectHeight . '&format=' . $saveFormat . '&outPath=' . $outPath;
     //sign URI
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
     //$json = json_decode($response);
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output === '') {
         $outputPath = AsposeApp::$outPutLocation . $this->getFileName();
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     } else {
         return false;
     }
 }
 /**
  * Executes mail merge template.
  *
  * @param string $fileName The name of source file.
  * @param string $strXML Data in xml format.
  * @param string $documentFolder The document folder.
  *
  * @return string Returns the file path.
  * @throws Exception
  */
 public function executeTemplate($fileName, $strXML, $documentFolder = '')
 {
     //check whether files are set or not
     if ($fileName == '') {
         throw new Exception('File not specified');
     }
     //build URI to execute mail merge template
     $strURI = Product::$baseProductUri . '/words/' . $fileName . '/executeTemplate' . ($documentFolder == '' ? '' : '?folder=' . $documentFolder);
     //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($documentFolder == '' ? $json->Document->FileName : $documentFolder . '/' . $json->Document->FileName);
         $outputPath = AsposeApp::$outPutLocation . $fileName;
         Utils::saveFile($outputStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 /**
  * Gets a specfied link on a specified document page
  *
  * @param integer $pageNumber Number of the page.
  * @param integer $linkIndex Index of the link.
  *
  * @return object
  * @throws Exception
  */
 public function getLink($pageNumber, $linkIndex)
 {
     $strURI = Product::$baseProductUri . '/pdf/' . $this->getFileName() . '/pages/' . $pageNumber . '/links/' . $linkIndex;
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
     $json = json_decode($responseStream);
     return $json->Link;
 }
 /**
  * Compare the currently active $this->fileName with the passed $compareWithFilename. Make sure
  * that $this->fileName does not have any pending revision changes.
  *
  * @see http://api.aspose.com/v1.1/swagger/ui/index#!/words/WordsDocumentSaveAs_PostDocumentSaveAs
  *
  * @param string $compareWithFilename
  * @param array $compareData
  * @param array $options
  *
  * @return bool
  * @throws Exception
  */
 public function compareDocument($compareWithFilename, array $compareData = array(), array $options = array())
 {
     // POST parameters
     $resolver = new OptionsResolver();
     $resolver->setDefault('ComparingWithDocument', $compareWithFilename)->setRequired(array('Author'))->setDefined(array('DateTime'));
     $compareData = json_encode($resolver->resolve($compareData));
     // GET parameters
     $resolver = new OptionsResolver();
     $resolver->setDefined(array('filename', 'storage', 'folder'));
     $options = $resolver->resolve($options);
     // Create request with resolved POST and GET parameters
     $strURI = Product::$baseProductUri . '/words/' . $this->getFileName() . '/compareDocument?' . http_build_query($options);
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'POST', 'JSON', $compareData);
     $json = json_decode($responseStream);
     if ($json->Code == 200 && isset($json->Document)) {
         $outputFile = $json->Document->FileName;
         $folder = new Folder();
         $outputStream = $folder->getFile($outputFile);
         $outputPath = AsposeApp::$outPutLocation . $outputFile;
         Utils::saveFile($outputStream, $outputPath);
         return $outputPath;
     }
     AsposeApp::getLogger()->warning('Error occured while processing `compareDocument` command, HTTP 200 code or result `Document` was not found.', array('json-code' => $json->Code));
     return false;
 }
 /**
  * Extract OCR or HOCR Text from image url.
  *
  * @param string $url URL of the image.
  * @param string $language Language of document to recogniize.
  * @param string $useDefaultDictionaries Allows to correct text after
  * recognition using default dictionaries.
  *
  * @return object
  */
 public function extractTextFromUrl($url, $language, $useDefaultDictionaries)
 {
     $strURI = Product::$baseProductUri . '/ocr/recognize?url=' . $url . '&language=' . $language . '&useDefaultDictionaries=' . $useDefaultDictionaries;
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI);
     $json = json_decode($responseStream);
     return $json;
 }
 public function convertLocalFile($inputFile = '', $outputFilename = '', $outputFormat = '')
 {
     //check whether file is set or not
     if ($inputFile == '') {
         throw new Exception('No file name specified');
     }
     if ($outputFormat == '') {
         throw new Exception('output format not specified');
     }
     $strURI = Product::$baseProductUri . '/pdf/convert?format=' . $outputFormat;
     if (!file_exists($inputFile)) {
         throw new Exception('input file doesnt exist.');
     }
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::uploadFileBinary($signedURI, $inputFile, 'xml');
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output === '') {
         if ($outputFormat == 'html') {
             $saveFormat = 'zip';
         } else {
             $saveFormat = $outputFormat;
         }
         if ($outputFilename == '') {
             $outputFilename = Utils::getFileName($inputFile) . '.' . $saveFormat;
         }
         $outputPath = AsposeApp::$outPutLocation . $outputFilename;
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 /**
  * Update Bookmark Text of a Word
  * 
  * @return boolean
  * @throws Exception
  */
 public function updateBookmark($bookmarkName, $bookmarkText)
 {
     if ($bookmarkName == '') {
         throw new Exception('Bookmark name not specified');
     }
     if ($bookmarkText == '') {
         throw new Exception('Bookmark text not specified');
     }
     //build URI
     $strURI = Product::$baseProductUri . '/words/' . $this->getFileName() . '/bookmarks/' . $bookmarkName;
     //sign URI
     $signedURI = Utils::sign($strURI);
     $post_data_arr['Text'] = $bookmarkText;
     $postData = json_encode($post_data_arr);
     $responseStream = Utils::processCommand($signedURI, 'POST', 'JSON', $postData);
     $json = json_decode($responseStream);
     if ($json->Code == 200) {
         return true;
     }
     AsposeApp::getLogger()->warning('Error occured, http 200 code was not found.', array('json-code' => $json->Code));
     return false;
 }
 /**
  * Clear Cells Formatting in Excel Worksheet
  * 
  * @param type $startRow Start row index.
  * @param type $startColumn Start column index.
  * @param type $endRow End row index.
  * @param type $endColumn End column index.
  * 
  * @return string Returns the file path.
  * @throws Exception
  */
 public function clearCellsFormatting($startRow, $startColumn, $endRow, $endColumn)
 {
     if ($startRow == '') {
         throw new Exception('Start Row not specified');
     }
     if ($startColumn == '') {
         throw new Exception('Start Column not specified');
     }
     if ($endRow == '') {
         throw new Exception('End Row not specified');
     }
     if ($endColumn == '') {
         throw new Exception('End Column not specified');
     }
     //Build URI
     $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() . '/worksheets/' . $this->worksheetName . '/cells/ClearFormats?startRow=' . $startRow . '&startColumn=' . $startColumn . '&endRow=' . $endRow . '&endColumn=' . $endColumn;
     //Sign URI
     $signedURI = Utils::sign($strURI);
     //Send request and receive response stream
     $responseStream = Utils::processCommand($signedURI, 'POST', '', '');
     $v_output = Utils::validateOutput($responseStream);
     if ($v_output == '') {
         $strURI = Product::$baseProductUri . '/storage/file/' . $this->getFileName();
         $signedURI = Utils::Sign($strURI);
         $responseStream = Utils::processCommand($signedURI, "GET", "", "");
         $outputPath = AsposeApp::$outPutLocation . $this->getFileName();
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }
 public function splitPagesToAnyFormat($from, $to, $format)
 {
     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;
     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 = $this->fileName . '_' . $i . '.' . $format;
         $outputFile = AsposeApp::$outPutLocation . $fileName;
         Utils::saveFile($responseStream, $outputFile);
         echo $outputFile . '<br />';
         $i++;
     }
 }
 /**
  * Convert web pages to Word Documents
  * 
  * @param XML $strXML Provide XML data.
  * 
  * @return string
  * @throws Exception
  */
 public function convertWebPages($strXML)
 {
     if ($strXML == '') {
         throw new Exception('XML not specified');
     }
     //build URI
     $strURI = Product::$baseProductUri . '/words/loadWebDocument';
     //sign URI
     $signedURI = Utils::sign($strURI);
     $responseStream = Utils::processCommand($signedURI, 'POST', 'XML', $strXML);
     $xml = simplexml_load_string($responseStream);
     if ($xml->Status == 'OK') {
         $fileName = $xml->SaveResult->Dest['href'];
         $strURI = Product::$baseProductUri . '/storage/file/' . $fileName;
         $signedURI = Utils::Sign($strURI);
         $responseStream = Utils::processCommand($signedURI, "GET", "", "");
         $outputPath = AsposeApp::$outPutLocation . $fileName;
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     } else {
         return false;
     }
 }
 /**
  * Saves a specific auto-shape from a specific sheet as image.
  *
  * @param string $worksheetName Name of the sheet.
  * @param integer $shapeIndex Index of the shape.
  * @param string $imageFormat Returns image in the specified format.
  *
  * @return string Returns the file path.
  * @throws Exception
  */
 public function getAutoShape($worksheetName, $shapeIndex, $imageFormat)
 {
     //Build URI
     $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() . '/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 = AsposeApp::$outPutLocation . Utils::getFileName($this->getFileName()) . '_' . $worksheetName . '.' . $imageFormat;
         Utils::saveFile($responseStream, $outputPath);
         return $outputPath;
     } else {
         return $v_output;
     }
 }