public static function extractContentBetweenBlockLevelNodes() { //ExStart //ExId:ExtractBetweenNodes_BetweenNodes //ExSummary:Shows how to extract the content between a paragraph and table using the ExtractContent method. // Load in the document $doc = new Java("com.aspose.words.Document", ExtractContent::$gDataDir . "TestFile.doc"); $nodeType = Java("com.aspose.words.NodeType"); $startPara = $doc->getLastSection()->getChild($nodeType->PARAGRAPH, 2, true); $endTable = $doc->getLastSection()->getChild($nodeType->TABLE, 0, true); // Extract the content between these nodes in the document. Include these markers in the extraction. $extractedNodes = ExtractContent::ExtractContents($startPara, $endTable, true); // Lets reverse the array to make inserting the content back into the document easier. $collections = new Java("java.util.Collections"); $collections->reverse($extractedNodes); while (java_values($extractedNodes->size()) > 0) { // Insert the last node from the reversed list $endTable->getParentNode()->insertAfter($extractedNodes->get(0), $endTable); // Remove this node from the list after insertion. $extractedNodes->remove(0); } // Save the generated document to disk. $doc->save(ExtractContent::$gDataDir . "TestFile.DuplicatedContent Out.doc"); //ExEnd }
public static function main() { // Create a new document. $doc = new Java("com.aspose.words.Document"); // Creates and adds a paragraph node to the document. $para = new Java("com.aspose.words.Paragraph", $doc); // Typed access to the last section of the document. $section = $doc->getLastSection(); $section->getBody()->appendChild($para); // Next print the node type of one of the nodes in the document. $nodeType = $doc->getFirstSection()->getBody()->getNodeType(); $node = new Java("com.aspose.words.Node"); echo "NodeType: " . $node->nodeTypeToString($nodeType); }
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"); }
public static function DifferentPageSetup() { //ExStart //ExId:AppendDocument_DifferentPageSetup //ExSummary:Shows how to append a document to another document continuously which has different page settings. $dstDoc = new Java("com.aspose.words.Document", AppendDocument::$gDataDir . "TestFile.Destination.doc"); $srcDoc = new Java("com.aspose.words.Document", AppendDocument::$gDataDir . "TestFile.SourcePageSetup.doc"); // Set the source document to continue straight after the end of the destination document. // If some page setup settings are different then this may not work and the source document will appear // on a new page. $sectionStart = new Java("com.aspose.words.SectionStart"); $srcDoc->getFirstSection()->getPageSetup()->setSectionStart($sectionStart->CONTINUOUS); // To ensure this does not happen when the source document has different page setup settings make sure the // settings are identical between the last section of the destination document. // If there are further continuous sections that follow on in the source document then this will need to be // repeated for those sections as well. $srcDoc->getFirstSection()->getPageSetup()->setPageWidth($dstDoc->getLastSection()->getPageSetup()->getPageWidth()); $srcDoc->getFirstSection()->getPageSetup()->setPageHeight($dstDoc->getLastSection()->getPageSetup()->getPageHeight()); $srcDoc->getFirstSection()->getPageSetup()->setOrientation($dstDoc->getLastSection()->getPageSetup()->getOrientation()); $importFormatMode = new Java("com.aspose.words.ImportFormatMode"); $dstDoc->appendDocument($srcDoc, $importFormatMode->KEEP_SOURCE_FORMATTING); $dstDoc->save(AppendDocument::$gDataDir . "TestFile.DifferentPageSetup Out.doc"); //ExEnd }