Package com.aspose.words

Examples of com.aspose.words.Document


      // /* Info msg */
      // System.out.printf("Process request from : %s\n", request
      // .getRemoteAddr());
      /* Create a simple document */
      long start = System.currentTimeMillis();
      Document wordDoc = new Document();
      DocumentBuilder wordDocBuilder = new DocumentBuilder(wordDoc);
      // Add Header / Footer
      wordDocBuilder.getPageSetup().setDifferentFirstPageHeaderFooter(
          false);
      wordDocBuilder.getPageSetup().setOddAndEvenPagesHeaderFooter(false);
      wordDocBuilder.getPageSetup().setHeaderDistance(20);
      wordDocBuilder.getPageSetup().setFooterDistance(20);
      wordDocBuilder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
      wordDocBuilder.writeln("My HEADER");
      wordDocBuilder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
      wordDocBuilder.writeln("My FOOTER");
      wordDocBuilder.moveToDocumentEnd();
      // Set font properties
      wordDocBuilder.setBold(true);
      wordDocBuilder.setItalic(true);
      // Add text
      wordDocBuilder.writeln("My Text");
      wordDocBuilder.writeln();
      // Add end footer note and foot note
      wordDocBuilder.insertFootnote(FootnoteType.ENDNOTE, "My End Note");
      wordDocBuilder
          .insertFootnote(FootnoteType.FOOTNOTE, "My Foot Note");
      wordDocBuilder.writeln();
      // Add hyperlink
      wordDocBuilder.insertHyperlink("LINK", "http://www.google.lu",
          false);
      wordDocBuilder.writeln();
      // Add a table
      wordDocBuilder.startTable();
      // --Row 1 with 2 cell
      Cell cell = wordDocBuilder.insertCell();
      cell.getCellFormat().setVerticalAlignment(
          CellVerticalAlignment.CENTER);
      wordDocBuilder.writeln("Row 1 Cell 1 Text");
      cell = wordDocBuilder.insertCell();
      cell.getCellFormat().setVerticalAlignment(
          CellVerticalAlignment.CENTER);
      wordDocBuilder.writeln("Row 1 Cell 2 Text");
      wordDocBuilder.endRow();
      // --Row 2 with 2 cell
      cell = wordDocBuilder.insertCell();
      cell.getCellFormat().setVerticalAlignment(
          CellVerticalAlignment.BOTTOM);
      wordDocBuilder.writeln("Row 2 Cell 1 Text");
      cell = wordDocBuilder.insertCell();
      cell.getCellFormat()
          .setVerticalAlignment(CellVerticalAlignment.TOP);
      wordDocBuilder.writeln("Row 2 Cell 2 Text");
      wordDocBuilder.endRow();
      // --Row 3 with 3 cell merged
      cell = wordDocBuilder.insertCell();
      cell.getCellFormat().setVerticalAlignment(
          CellVerticalAlignment.CENTER);
      cell.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
      cell.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
      wordDocBuilder.writeln("Row 3 Cell 3 Text");
      cell = wordDocBuilder.insertCell();
      cell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
      wordDocBuilder.endRow();
      wordDocBuilder.endTable();
      // Add Comment
      Comment comment = new Comment(wordDoc);
      comment.setAuthor("D.Righetto");
      comment.getParagraphs().add(new Paragraph(wordDoc));
      comment.getFirstParagraph().getRuns().add(
          new Run(wordDoc, "My Comment text !!!"));
      wordDocBuilder.getCurrentParagraph().appendChild(comment);
      // Add break
      wordDocBuilder.insertBreak(BreakType.PAGE_BREAK);
      // Add image
      String imgUrl = "http://" + request.getServerName() + ":"
          + request.getServerPort() + request.getContextPath()
          + "/img/AsposeWords.gif";
      // System.out.printf("Insert image from : %s\n", imgUrl);
      wordDocBuilder.insertImage(imgUrl);
      System.out.printf("Document generated in %s ms\n", (System
          .currentTimeMillis() - start));

      /* Send document to client */
      response.setContentType("application/vnd.ms-word");
      response.addHeader("Content-Disposition",
          "inline;filename=myWordDocument.doc");
      wordDoc.save(response.getOutputStream(), SaveFormat.DOC);
      response.flushBuffer();
    } catch (Exception e) {
      throw new ServletException(e);
    }

View Full Code Here


      String dotUrl = "http://" + request.getServerName() + ":"
          + request.getServerPort() + request.getContextPath()
          + "/dot/MODELE_VIDE_FR.dot";
      dotUrl = "D:\\TMP\\ACC_RECEP_REFERE_IT.dot";
      long start = System.currentTimeMillis();
      Document wordDoc = new Document(dotUrl);

      // /* Replace bookmark value */
      // Get document bookmarks collection
      // Bookmarks bookmarks = wordDoc.getRange().getBookmarks();
      // for (int i = 0; i < bookmarks.getCount(); i++) {
      // Bookmark bookmark = bookmarks.get(i);
      // String value = "VALUE_" + Integer.toString(i);
      // System.out.printf(
      // "Processing bookmark['%s'] : ['%s'] to ['%s']\n",
      // bookmark.getName(), bookmark.getText(), value);
      // bookmark.setText(value);
      // }
      // /* Replace text directly */
      // int count = wordDoc.getRange().replace("DATE_DEP_AFF_FAX",
      // "DOMINIQUE", true, true);
      // System.out.printf("%s items replaced !\n", count);
      /* Replace text fields */
      FormFields formFields = wordDoc.getRange().getFormFields();
      for (int i = 0; i < formFields.getCount(); i++) {
        FormField formField = formFields.get(i);
        String value = "VALUE_" + Integer.toString(i);
        System.out.printf("Processing FormFiled['%s'] to ['%s']\n",
            formField.getName(), value);
        int count = formField.getDocument().getRange().replace(
            formField.getName(), value, true, true);
        System.out.printf("%s items replaced !\n", count);
      }

      System.out.printf("Document modified in %s ms\n", (System
          .currentTimeMillis() - start));

      /* Send document to client */
      response.setContentType("application/vnd.ms-word");
      response.addHeader("Content-Disposition",
          "inline;filename=myWordDocument.doc");
      wordDoc.save(response.getOutputStream(), SaveFormat.DOC);
      response.flushBuffer();
    } catch (Exception e) {
      throw new ServletException(e);
    }
  }
View Full Code Here

public class AsposeMovingCursor
{
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document("data/document.doc");
    DocumentBuilder builder = new DocumentBuilder(doc);

    //Shows how to access the current node in a document builder.
    Node curNode = builder.getCurrentNode();
    Paragraph curParagraph = builder.getCurrentParagraph();
   
    // Shows how to move a cursor position to a specified node.
    builder.moveTo(doc.getFirstSection().getBody().getLastParagraph());
   
    // Shows how to move a cursor position to the beginning or end of a document.
    builder.moveToDocumentEnd();
    builder.writeln("This is the end of the document.");

    builder.moveToDocumentStart();
    builder.writeln("This is the beginning of the document.");
   
    doc.save("data/AsposeMovingCursor.doc");
   
    System.out.println("Done.");
  }
View Full Code Here

public class AsposeJoiningTables
{
  public static void main(String[] args) throws Exception
  {
    // Load the document.
    Document doc = new Document("data/tableDoc.doc");

    // Get the first and second table in the document.
    // The rows from the second table will be appended to the end of the first table.
    Table firstTable = (Table)doc.getChild(NodeType.TABLE, 0, true);
    Table secondTable = (Table)doc.getChild(NodeType.TABLE, 1, true);

    // Append all rows from the current table to the next.
    // Due to the design of tables even tables with different cell count and widths can be joined into one table.
    while (secondTable.hasChildNodes())
        firstTable.getRows().add(secondTable.getFirstRow());

    // Remove the empty table container.
    secondTable.remove();

    doc.save("data/AsposeJoinTables.doc");
  }
View Full Code Here

public class AsposeComments
{
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.write("Some text is added.");

    Comment comment = new Comment(doc, "Aspose", "As", new Date());
    builder.getCurrentParagraph().appendChild(comment);
    comment.getParagraphs().add(new Paragraph(doc));
    comment.getFirstParagraph().getRuns().add(new Run(doc, "Comment text."));

    doc.save("data/docx4j/Aspose_Comments.docx");
    System.out.println("Done.");
  }
View Full Code Here

{
  // See more @ http://www.aspose.com/docs/display/wordsjava/Bookmarks+in+Aspose.Words
 
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
   
    builder.startBookmark("AsposeBookmark");
    builder.writeln("Text inside a bookmark.");
    builder.endBookmark("AsposeBookmark");
   
    // By index.
    Bookmark bookmark1 = doc.getRange().getBookmarks().get(0);
   
    // By name.
    Bookmark bookmark2 = doc.getRange().getBookmarks().get("AsposeBookmark");
   
    doc.save("data/docx4j/Aspose_Bookmark.doc", SaveFormat.DOC);
    System.out.println("Done.");
  }
View Full Code Here

public class AsposeConvertToFormats
{
  public static void main(String[] args) throws Exception
  {
    // Load the document from disk.
    Document doc = new Document("data/docx4j/document.doc");
   
    doc.save("data/docx4j/html/Aspose_DocToHTML.html",SaveFormat.HTML); //Save the document in HTML format.
    doc.save("data/docx4j/Aspose_DocToPDF.pdf",SaveFormat.PDF); //Save the document in PDF format.
    doc.save("data/docx4j/Aspose_DocToTxt.txt",SaveFormat.TEXT); //Save the document in TXT format.
    doc.save("data/docx4j/Aspose_DocToJPG.jpg",SaveFormat.JPEG); //Save the document in JPEG format.
       
        System.out.println("Aspose - Doc file converted in specified formats");
  }
View Full Code Here

public class AsposeProtectDoc
{
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document("data/document.doc");
    doc.protect(ProtectionType.READ_ONLY);
//    doc.protect(ProtectionType.ALLOW_ONLY_COMMENTS);
//    doc.protect(ProtectionType.ALLOW_ONLY_FORM_FIELDS);
//    doc.protect(ProtectionType.ALLOW_ONLY_REVISIONS);
   
    doc.save("data/AsposeProtect.doc", SaveFormat.DOC);
  }
View Full Code Here

public class AsposeCloneDoc
{
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document("data/document.doc");
    Document clone = doc.deepClone();
    clone.save("data/AsposeClone.doc", SaveFormat.DOC);
  }
View Full Code Here

{
  // See more @ http://www.aspose.com/docs/display/wordsjava/Bookmarks+in+Aspose.Words
 
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document("data/docx4j/Aspose_Bookmark.doc");

    // By name.
    Bookmark bookmark = doc.getRange().getBookmarks().get("AsposeBookmark");
    bookmark.remove();
   
    doc.save("data/docx4j/Aspose_BookmarkDeleted.doc", SaveFormat.DOC);
    System.out.println("Done.");
  }
View Full Code Here

TOP

Related Classes of com.aspose.words.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.