Esempio n. 1
0
 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);
 }
 public static function main()
 {
     $dataDir = "/usr/local/apache-tomcat-8.0.22/webapps/JavaBridge/Aspose_Words_Java_For_PHP/src/mailmergeandreporting/mailmergeformfields/data/";
     $doc = new Document($dataDir . "Template.doc");
     $doc->getMailMerge()->setFieldMergingCallback(new HandleMergeField());
     $fieldNames = array("RecipientName", "SenderName", "FaxNumber", "PhoneNumber", "Subject", "Body", "Urgent", "ForReview", "PleaseComment");
     $fieldValues = array("Josh", "Jenny", "123456789", "", "Hello", "Test Pakistan 1", true, false, true);
     $doc->getMailMerge()->execute($fieldNames, $fieldValues);
     $doc->save($dataDir . "Template Out.doc");
 }