예제 #1
0
 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);
 }
예제 #2
0
 public static function autoFitTableToFixedColumnWidths($dataDir)
 {
     //ExStart
     //ExFor:Table.AutoFit
     //ExFor:AutoFitBehavior
     //ExId:DisableAutoFitAndUseFixedWidths
     //ExSummary:Disables autofitting and enables fixed widths for the specified table.
     // Open the document
     $doc = new Java("com.aspose.words.Document", $dataDir . "TestFile.doc");
     $nodeType = new Java("com.aspose.words.NodeType");
     $table = $doc->getChild($nodeType->TABLE, 0, true);
     // Disable autofitting on this table.
     $autoFitBehavior = new Java("com.aspose.words.AutoFitBehavior");
     $table->autoFit($autoFitBehavior->AUTO_FIT_TO_CONTENTS);
     // Save the document to disk.
     $doc->save($dataDir . "TestFile.FixedWidth Out.doc");
     //ExEnd
     $preferredWidthType = new Java("com.aspose.words.PreferredWidthType");
     if (java_values($doc->getFirstSection()->getBody()->getTables()->get(0)->getPreferredWidth()->getType()) == java_values($preferredWidthType->AUTO)) {
         echo "PreferredWidth type is not auto <br />";
     }
     if (java_values($doc->getFirstSection()->getBody()->getTables()->get(0)->getPreferredWidth()->getValue()) == 0) {
         echo "PreferredWidth value is not 0 <br />";
     }
     if (java_values($doc->getFirstSection()->getBody()->getTables()->get(0)->getFirstRow()->getFirstCell()->getCellFormat()->getWidth()) == 0) {
         echo "Cell width is not correct. <br />";
     }
 }
예제 #3
0
 public static function ConvertNumPageFields()
 {
     $dstDoc = new Java("com.aspose.words.Document", AppendDocument::$gDataDir . "TestFile.Destination.doc");
     $srcDoc = new Java("com.aspose.words.Document", AppendDocument::$gDataDir . "TestFile.Source.doc");
     // Restart the page numbering on the start of the source document.
     $srcDoc->getFirstSection()->getPageSetup()->setRestartPageNumbering(true);
     $srcDoc->getFirstSection()->getPageSetup()->setPageStartingNumber(1);
     // Append the source document to the end of the destination document.
     $importFormatMode = new Java("com.aspose.words.ImportFormatMode");
     $dstDoc->appendDocument($srcDoc, $importFormatMode->KEEP_SOURCE_FORMATTING);
     // After joining the documents the NUMPAGE fields will now display the total number of pages which
     // is undesired behaviour. Call this method to fix them by replacing them with PAGEREF fields.
     AppendDocument::convertNumPageFieldsToPageRef($dstDoc);
     // This needs to be called in order to update the new fields with page numbers.
     $dstDoc->updatePageLayout();
     $dstDoc->save(AppendDocument::$gDataDir . "TestFile.ConvertNumPageFields Out.doc");
 }
예제 #4
0
 public static function generateDocument($srcDoc, $nodes)
 {
     // Create a blank document.
     $dstDoc = new Java("com.aspose.words.Document");
     // Remove the first paragraph from the empty document.
     $dstDoc->getFirstSection()->getBody()->removeAllChildren();
     // Import each node from the list into the new document. Keep the original formatting of the node.
     $importFormatMode = Java("com.aspose.words.ImportFormatMode");
     $importer = new Java("com.aspose.words.NodeImporter", $srcDoc, $dstDoc, $importFormatMode->KEEP_SOURCE_FORMATTING);
     foreach ($nodes as $node) {
         $importNode = $importer->importNode($node, true);
         $dstDoc->getFirstSection()->getBody()->appendChild($importNode);
     }
     // Return the generated document.
     return $dstDoc;
 }