예제 #1
0
 public static function replaceText()
 {
     // The path to the documents directory.
     $dataDir = "/usr/local/apache-tomcat-8.0.22/webapps/JavaBridge/Aspose_Words_Java_For_PHP/src/quickstart/findandreplace/data/";
     // Open the document.
     $doc = new Java("com.aspose.words.Document", $dataDir . "ReplaceSimple.doc");
     // Check the text of the document
     echo "Original document text: " . $doc->getRange()->getText() . "<BR>";
     // Replace the text in the document.
     $doc->getRange()->replace("_CustomerName_", "James Bond", false, false);
     // Check the replacement was made.
     echo "Document text after replace: " . $doc->getRange()->getText();
     // Save the modified document.
     $doc->save($dataDir . "ReplaceSimple Out.doc");
 }
예제 #2
0
 public static function main()
 {
     // The path to the documents directory.
     $dataDir = "/usr/local/apache-tomcat-8.0.22/webapps/JavaBridge/Aspose_Words_Java_For_PHP/src/programmingwithdocuments/workingwithfields/removefield/data/";
     $doc = new Java("com.aspose.words.Document", $dataDir . "Field.RemoveField.doc");
     //ExStart
     //ExFor:Field.Remove
     //ExId:DocumentBuilder_RemoveField
     //ExSummary:Removes a field from the document.
     $field = $doc->getRange()->getFields()->get(0);
     // Calling this method completely removes the field from the document.
     $field->remove();
     //ExEnd
 }
예제 #3
0
 public static function main()
 {
     //$color = Java("java.awt.Color");
     //echo java_values($color->YELLOW); exit;
     // The path to the documents directory.
     $dataDir = "/usr/local/apache-tomcat-8.0.22/webapps/JavaBridge/Aspose_Words_Java_For_PHP/src/programmingwithdocuments/usingfindandreplace/findandhighlight/data/";
     $doc = new Java("com.aspose.words.Document", $dataDir . "TestFile.doc");
     // We want the "your document" phrase to be highlighted.
     $pattern = new Java("java.util.regex.Pattern");
     $regex = $pattern->compile("your document", $pattern->CASE_INSENSITIVE);
     $replaceEvaluation = new ReplaceEvaluatorFindAndHighlight();
     $range = $doc->getRange();
     $range->replace($regex, java_values($replaceEvaluation));
     // Save the output document.
     $doc->save($dataDir . "TestFile Out.doc");
 }
 public static function main()
 {
     $dataDir = "/usr/local/apache-tomcat-8.0.22/webapps/JavaBridge/Aspose_Words_Java_For_PHP/src/programmingwithdocuments/workingwithbookmarks/copybookmarkedtext/data/";
     // Load the source document.
     $srcDoc = new Java("com.aspose.words.Document", $dataDir . "Template.doc");
     // This is the bookmark whose content we want to copy.
     $srcBookmark = $srcDoc->getRange()->getBookmarks()->get("ntf010145060");
     // We will be adding to this document.
     $dstDoc = new Java("com.aspose.words.Document");
     // Let's say we will be appending to the end of the body of the last section.
     $dstNode = $dstDoc->getLastSection()->getBody();
     // It is a good idea to use this import context object because multiple nodes are being imported.
     // If you import multiple times without a single context, it will result in many styles created.
     $importFormatMode = java('com.aspose.words.ImportFormatMode');
     $importer = new Java("com.aspose.words.NodeImporter", $srcDoc, $dstDoc, $importFormatMode->KEEP_SOURCE_FORMATTING);
     // Do it once.
     CopyBookmarkedText::appendBookmarkedText($importer, $srcBookmark, $dstNode);
     // Do it one more time for fun.
     CopyBookmarkedText::appendBookmarkedText($importer, $srcBookmark, $dstNode);
     // Save the finished document.
     $dstDoc->save($dataDir . "Template Out.doc");
 }
예제 #5
0
 public static function extractContentBetweenBookmark()
 {
     //ExStart
     //ExId:ExtractBetweenNodes_BetweenBookmark
     //ExSummary:Shows how to extract the content referenced a bookmark using the ExtractContent method.
     // Load in the document
     $doc = new Java("com.aspose.words.Document", ExtractContent::$gDataDir . "TestFile.doc");
     // Retrieve the bookmark from the document.
     $bookmark = $doc->getRange()->getBookmarks()->get("Bookmark1");
     // We use the BookmarkStart and BookmarkEnd nodes as markers.
     $bookmarkStart = $bookmark->getBookmarkStart();
     $bookmarkEnd = $bookmark->getBookmarkEnd();
     // Firstly extract the content between these nodes including the bookmark.
     $extractedNodesInclusive = ExtractContent::ExtractContents($bookmarkStart, $bookmarkEnd, true);
     $dstDoc = ExtractContent::generateDocument($doc, $extractedNodesInclusive);
     $dstDoc->save(ExtractContent::$gDataDir . "TestFile.BookmarkInclusive Out.doc");
     // Secondly extract the content between these nodes this time without including the bookmark.
     $extractedNodesExclusive = ExtractContent::ExtractContents($bookmarkStart, $bookmarkEnd, false);
     $dstDoc = ExtractContent::generateDocument($doc, $extractedNodesExclusive);
     $dstDoc->save(ExtractContent::$gDataDir . "TestFile.BookmarkExclusive Out.doc");
     //ExEnd
 }