예제 #1
0
 public static function printHelloWorld()
 {
     // The path to the documents directory.
     $dataDir = "/usr/local/apache-tomcat-8.0.22/webapps/JavaBridge/Aspose_Words_Java_For_PHP/src/quickstart/helloworld/data/";
     // Create a blank document.
     $documentObject = new Java("com.aspose.words.Document");
     // DocumentBuilder provides members to easily add content to a document.
     $builderBoject = new Java("com.aspose.words.DocumentBuilder", $documentObject);
     // Write a new paragraph in the document with the text "Hello World!"
     $builderBoject->writeln("Hello World!");
     // Save the document in DOCX format. The format to save as is inferred from the extension of the file name.
     // Aspose.Words supports saving any document in many more formats.
     $documentObject->save($dataDir . "HelloWorld.docx");
 }
예제 #2
0
 public static function update()
 {
     // The path to the documents directory.
     $dataDir = "/usr/local/apache-tomcat-8.0.22/webapps/JavaBridge/Aspose_Words_Java_For_PHP/src/quickstart/updatefields/data/";
     // Demonstrates how to insert fields and update them using Aspose.Words.
     // First create a blank document.
     $doc = new Java("com.aspose.words.Document");
     // Use the document builder to insert some content and fields.
     $builder = new Java("com.aspose.words.DocumentBuilder", $doc);
     // Insert a table of contents at the beginning of the document.
     $builder->insertTableOfContents("\\o \"1-3\" \\h \\z \\u");
     $builder->writeln();
     // Insert some other fields.
     $builder->write("Page: ");
     $builder->insertField("PAGE");
     $builder->write(" of ");
     $builder->insertField("NUMPAGES");
     $builder->writeln();
     $builder->write("Date: ");
     $builder->insertField("DATE");
     // Start the actual document content on the second page.
     $breakType = new Java("com.aspose.words.BreakType");
     $builder->insertBreak($breakType->SECTION_BREAK_NEW_PAGE);
     // Build a document with complex structure by applying different heading styles thus creating TOC entries.
     $styleIdentifier = new Java("com.aspose.words.StyleIdentifier");
     $builder->getParagraphFormat()->setStyleIdentifier($styleIdentifier->HEADING_1);
     $builder->writeln("Heading 1");
     $builder->getParagraphFormat()->setStyleIdentifier($styleIdentifier->HEADING_2);
     $builder->writeln("Heading 1.1");
     $builder->writeln("Heading 1.2");
     $builder->getParagraphFormat()->setStyleIdentifier($styleIdentifier->HEADING_1);
     $builder->writeln("Heading 2");
     $builder->writeln("Heading 3");
     // Move to the next page.
     $builder->insertBreak($breakType->PAGE_BREAK);
     $builder->getParagraphFormat()->setStyleIdentifier($styleIdentifier->HEADING_2);
     $builder->writeln("Heading 3.1");
     $builder->getParagraphFormat()->setStyleIdentifier($styleIdentifier->HEADING_3);
     $builder->writeln("Heading 3.1.1");
     $builder->writeln("Heading 3.1.2");
     $builder->writeln("Heading 3.1.3");
     $builder->getParagraphFormat()->setStyleIdentifier($styleIdentifier->HEADING_2);
     $builder->writeln("Heading 3.2");
     $builder->writeln("Heading 3.3");
     echo "Updating all fields in the document.";
     // Call the method below to update the TOC.
     $doc->updateFields();
     $doc->save($dataDir . "Document Field Update Out.docx");
 }