Package com.aspose.words

Examples of com.aspose.words.DocumentBuilder


      // 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");
 
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 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.
View Full Code Here

  {
    // Load the document.
    Document doc = new Document();
   
    // DocumentBuilder provides members to easily add content to a document.
    DocumentBuilder builder = new DocumentBuilder(doc);
    // Write a new paragraph in the document with some text as "Sample Content..."
    builder.setBold(true);
    builder.writeln("Aspose Sample Content for Word file.\r More Sample");

    String text = doc.getText();
    System.out.println("Doc Text: " + text);

    //Replace "\r" control character with "\r\n"
View Full Code Here

public class AsposePageBorders
{
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    PageSetup pageSetup = builder.getPageSetup();
    pageSetup.setTopMargin(ConvertUtil.inchToPoint(0.5));
    pageSetup.setBottomMargin(ConvertUtil.inchToPoint(0.5));
    pageSetup.setLeftMargin(ConvertUtil.inchToPoint(0.5));
    pageSetup.setRightMargin(ConvertUtil.inchToPoint(0.5));
    pageSetup.setHeaderDistance(ConvertUtil.inchToPoint(0.2));
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/AsposeComments.docx");
  }
View Full Code Here

public class AsposeFooters
{
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document();
      DocumentBuilder builder = new DocumentBuilder(doc);

      Section currentSection = builder.getCurrentSection();
      PageSetup pageSetup = currentSection.getPageSetup();

      // Specify if we want headers/footers of the first page to be different from other pages.
      // You can also use PageSetup.OddAndEvenPagesHeaderFooter property to specify
      // different headers/footers for odd and even pages.
      pageSetup.setDifferentFirstPageHeaderFooter(true);

      // --- Create header for the first page. ---
      pageSetup.setHeaderDistance(20);
      builder.moveToHeaderFooter(HeaderFooterType.FOOTER_FIRST);
      builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

      // Set font properties for header text.
      builder.getFont().setName("Arial");
      builder.getFont().setBold(true);
      builder.getFont().setSize(14);
     
      // Specify header title for the first page.
      builder.write("(C) 2001 Aspose Pty Ltd. All rights reserved.");

      // Save the resulting document.
      doc.save("data/AsposeFooter.doc");
  }
View Full Code Here

public class AsposeInsertImage
{
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    builder.insertImage("data/background.jpg");
    builder.insertImage("data/background.jpg",
            RelativeHorizontalPosition.MARGIN,
            100,
            RelativeVerticalPosition.MARGIN,
            200,
            200,
View Full Code Here

public class AsposeHeaders
{
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document();
      DocumentBuilder builder = new DocumentBuilder(doc);

      Section currentSection = builder.getCurrentSection();
      PageSetup pageSetup = currentSection.getPageSetup();

      // Specify if we want headers/footers of the first page to be different from other pages.
      // You can also use PageSetup.OddAndEvenPagesHeaderFooter property to specify
      // different headers/footers for odd and even pages.
      pageSetup.setDifferentFirstPageHeaderFooter(true);

      // --- Create header for the first page. ---
      pageSetup.setHeaderDistance(20);
      builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
      builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

      // Set font properties for header text.
      builder.getFont().setName("Arial");
      builder.getFont().setBold(true);
      builder.getFont().setSize(14);
      // Specify header title for the first page.
      builder.write("Aspose.Words Header/Footer Creation Primer - Title Page.");

      // Save the resulting document.
      doc.save("data/AsposeHeader.doc");
  }
View Full Code Here

TOP

Related Classes of com.aspose.words.DocumentBuilder

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.