Esempio n. 1
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 />";
     }
 }
 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/workingwithimages/compressimages/data/";
     $srcFileName = $dataDir . "Test.docx";
     $messageFormat = new Java("java.text.MessageFormat");
     $file_size = CompressImages::getFileSize($srcFileName);
     echo java_values($messageFormat->format("Loading {0}. Size {1}.", $srcFileName, $file_size));
     die("I M HERE");
     $doc = new Java("com.aspose.words.Document", $srcFileName);
     // 220ppi Print - said to be excellent on most printers and screens.
     // 150ppi Screen - said to be good for web pages and projectors.
     // 96ppi Email - said to be good for minimal document size and sharing.
     $desiredPpi = 150;
     // In Java this seems to be a good compression / quality setting.
     $jpegQuality = 90;
     // Resample images to desired ppi and save.
     $resampler = new Java("com.aspose.words.Resampler");
     $count = $resampler->resample($doc, $desiredPpi, $jpegQuality);
     echo $MessageFormat->format("Resampled {0} images.", $count);
     if ($count != 1) {
         echo "<br> We expected to have only 1 image resampled in this test document!";
     }
     $dstFileName = $srcFileName . "Resampled Out.docx";
     $doc->save($dstFileName);
     echo $messageFormat->format("Saving {0}. Size {1}.", $dstFileName, CompressImages::getFileSize($dstFileName));
     // Verify that the first image was compressed by checking the new Ppi.
     $doc = new Java("com.aspose.words.Document", $dstFileName);
     $nodeType = new Java("com.aspose.words.NodeType");
     $shape = $doc->getChild($nodeType->DRAWING_ML, 0, true);
     $convertUtil = new Java("com.aspose.words.ConvertUtil");
     $imagePpi = $shape->getImageData()->getImageSize()->getWidthPixels() / $convertUtil->pointToInch($shape->getSize()->getX());
     if ($imagePpi < 150) {
         echo "Image was not resampled successfully.";
     }
 }
 public static function extractContentBetweenCommentRange()
 {
     //ExStart
     //ExId:ExtractBetweenNodes_BetweenComment
     //ExSummary:Shows how to extract content referenced by a comment using the ExtractContent method.
     // Load in the document
     $doc = new Java("com.aspose.words.Document", ExtractContent::$gDataDir . "TestFile.doc");
     // This is a quick way of getting both comment nodes.
     // Your code should have a proper method of retrieving each corresponding start and end node.
     $nodeType = Java("com.aspose.words.NodeType");
     $commentStart = $doc->getChild($nodeType->COMMENT_RANGE_START, 0, true);
     $commentEnd = $doc->getChild($nodeType->COMMENT_RANGE_END, 0, true);
     // Firstly extract the content between these nodes including the comment as well.
     $extractedNodesInclusive = ExtractContent::ExtractContents($commentStart, $commentEnd, true);
     $dstDoc = ExtractContent::generateDocument($doc, $extractedNodesInclusive);
     $dstDoc->save(ExtractContent::$gDataDir . "TestFile.CommentInclusive Out.doc");
     // Secondly extract the content between these nodes without the comment.
     $extractedNodesExclusive = ExtractContent::ExtractContents($commentStart, $commentEnd, false);
     $dstDoc = ExtractContent::generateDocument($doc, $extractedNodesExclusive);
     $dstDoc->save(ExtractContent::$gDataDir . "TestFile.CommentExclusive Out.doc");
     //ExEnd
 }