public static function run($dataDir = null)
 {
     # Create instance of Diagram
     $diagram = new Diagram($dataDir . "Drawing.vsd");
     # convert image into bytes array
     $fi = new File($dataDir . "star.png");
     $files = new Files();
     $file_content = $files->readAllBytes($fi->toPath());
     $shapes = $diagram->getPages()->getPage("Flow 1")->getShapes();
     $i = 0;
     $typeValue = new TypeValue();
     while ($i < (int) (string) $shapes->getCount()) {
         $shape = $shapes->get($i);
         # Filter shapes by type Foreign
         if ($shape->getType() == $typeValue->FOREIGN) {
             # replace picture shape
             $shape->getForeignData()->setValue($file_content);
         }
         $i += 1;
     }
     # Save diagram
     $saveFileFormat = new SaveFileFormat();
     $diagram->save($dataDir . "ReplacePictureShape.vdx", $saveFileFormat->VDX);
     print "Replaced picture shape successfully!" . PHP_EOL;
 }
 public static function SplitDocumentToPages(File $docName)
 {
     $folderName = $docName->getParent();
     $fileName = $docName->getName();
     $extensionName = $fileName->substring($fileName->lastIndexOf("."));
     $outFolder_obj = new File($folderName, "Out");
     $outFolder = $outFolder_obj->getAbsolutePath();
     echo "<BR> Processing document: " . $fileName . $extensionName;
     $doc = new Document($docName->getAbsolutePath());
     // Create and attach collector to the document before page layout is built.
     $layoutCollector = new LayoutCollector(doc);
     // This will build layout model and collect necessary information.
     $doc->updatePageLayout();
     // Split nodes in the document into separate pages.
     $splitter = new DocumentPageSplitter($layoutCollector);
     // Save each page to the disk as a separate document.
     for ($page = 1; $page <= java_values($doc->getPageCount()); $page++) {
         $pageDoc = $splitter->GetDocumentOfPage($page);
         $file_obj = new File($outFolder, MessageFormat::format("{0} - page{1} Out{2}", $fileName, $page, $extensionName));
         $abs_path = $file_obj->getAbsolutePath();
         $pageDoc->save($abs_path);
     }
     // Detach the collector from the document.
     $layoutCollector->setDocument(null);
 }
/** create a temporary directory for the lucene index files. Make sure
 * to create the tmpdir from Java so that the directory has
 * javabridge_tmp_t Security Enhanced Linux permission. Note that PHP
 * does not have access to tempfiles with java_bridge_tmp_t: PHP
 * inherits the rights from the HTTPD, usually httpd_tmp_t.
 */
function create_index_dir()
{
    global $tmp_file, $tmp_dir;
    $javaTmpdir = SYS::type()->getProperty("java.io.tmpdir");
    $tmpdir = (string) $javaTmpdir;
    $tmp_file = tempnam($tmpdir, "idx");
    $tmp_dir = new IO\File("{$tmp_file}.d");
    $tmp_dir->mkdir();
    return (string) $tmp_dir->toString();
}