/** * 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; } }
/** * 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 without using Aspose storage. * * @param string $inputPath The path of source file. * @param string $outputPath Path where you want to file after conversion. * @param string $outputFormat New file format. * * @return string Returns the file path. */ public function convertLocalFile($inputPath, $outputPath, $outputFormat) { $str_uri = Product::$baseProductUri . '/words/convert?format=' . $outputFormat; $signed_uri = Utils::sign($str_uri); $responseStream = Utils::uploadFileBinary($signed_uri, $inputPath, 'xml'); $v_output = Utils::validateOutput($responseStream); if ($v_output === '') { if ($outputFormat == 'html') { $saveFormat = 'zip'; } else { $saveFormat = $outputFormat; } if ($outputPath == '') { $outputPath = AsposeApp::$outPutLocation . Utils::getFileName($inputPath) . '.' . $saveFormat; } 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; } }
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; } }
/** * Saves a particular slide into various formats. * * @param integer $slideNumber The slide number. * @param string $outputPath The output directory path. * @param string $saveFormat Return the presentation in the specified format. * * @return string Returns the file path. * @throws Exception */ public function saveSlideAs($slideNumber, $outputPath, $saveFormat) { 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->getFileName() . '/slides/' . $slideNumber . '?format=' . $saveFormat; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, 'GET', '', ''); $v_output = Utils::validateOutput($responseStream); if ($v_output === '') { $output = $outputPath . Utils::getFileName($this->getFileName()) . '_' . $slideNumber . '.' . $saveFormat; Utils::saveFile($responseStream, $output); return $output; } else { return $v_output; } }
/** * 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; } }
/** * Resize Image without Storage. * * @param integer $backgroundColorIndex Index of the background color. * @param integer $pixelAspectRatio Pixel aspect ratio. * @param boolean $interlaced Specifies if image is interlaced. * @param string $outPath Name of the output file. * * @return string Returns the file path. * @throws Exception */ public function resizeImage($inputPath, $newWidth, $newHeight, $outputFormat) { //check whether files are set or not if ($inputPath == '') { throw new Exception('Base file not specified'); } if ($newWidth == '') { throw new Exception('New image width not specified'); } if ($newHeight == '') { throw new Exception('New image height not specified'); } if ($outputFormat == '') { throw new Exception('Format not specified'); } //build URI $strURI = Product::$baseProductUri . '/imaging/resize?newWidth=' . $newWidth . '&newHeight=' . $newHeight . '&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; } }
/** * 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; } }
/** * Auto Fit Rows in Excel Workbooks * * @param string $saveFormat Format for the output file. * * @return string Returns file path. */ public function autofitRows($saveFormat = "") { $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() . '?isAutoFit=true'; if ($saveFormat != '') { $strURI .= '&format=' . $saveFormat; } $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, 'GET', '', ''); $v_output = Utils::validateOutput($responseStream); if ($v_output === '') { if ($saveFormat == '') { $strURI = Product::$baseProductUri . '/storage/file/' . $this->getFileName(); $signedURI = Utils::Sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $outputPath = AsposeApp::$outPutLocation . $this->getFileName(); Utils::saveFile($responseStream, $outputFile); } else { $outputPath = AsposeApp::$outPutLocation . Utils::getFileName($this->getFileName()) . '.' . $saveFormat; 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; } }
/** * Convert drawing object to image. * * @param int $index The index of drawing object. * @param string $renderformat Returns object in the specified format. * * @return string Returns the file path. * @throws Exception */ public function convertDrawingObject($index, $renderFormat) { $strURI = Product::$baseProductUri . '/words/' . $this->getFileName() . '/drawingObjects/' . $index . '?format=' . $renderFormat; $signedURI = Utils::sign($strURI); $responseStream = Utils::processCommand($signedURI, 'GET', '', ''); $v_output = Utils::validateOutput($responseStream); if ($v_output === '') { $outputPath = AsposeApp::$outPutLocation . Utils::getFileName($this->getFileName()) . '_' . $index . '.' . $renderFormat; Utils::saveFile($responseStream, $outputPath); return $outputPath; } else { return $v_output; } }