Package com.aspose.words

Examples of com.aspose.words.Document


public class AsposeWorkingWithDocProps
{
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document("data/docx4j/document.doc");
   
    System.out.println("============ Built-in Properties ============");
    for (DocumentProperty prop : doc.getBuiltInDocumentProperties())
        System.out.println(MessageFormat.format("{0} : {1}", prop.getName(), prop.getValue()));
   
    System.out.println("============ Custom Properties ============");
    for (DocumentProperty prop : doc.getCustomDocumentProperties())
        System.out.println(MessageFormat.format("{0} : {1}", prop.getName(), prop.getValue()));
   
    FileFormatInfo info = FileFormatUtil.detectFileFormat("data/docx4j/document.doc");
    System.out.println("The document format is: " + FileFormatUtil.loadFormatToExtension(info.getLoadFormat()));
    System.out.println("Document is encrypted: " + info.isEncrypted());
View Full Code Here


public class AsposeAppendDocs
{
  public static void main(String[] args) throws Exception
  {
    Document doc1 = new Document("data/doc1.doc");
    Document doc2 = new Document("data/doc2.doc");
   
    doc1.appendDocument(doc2, ImportFormatMode.KEEP_SOURCE_FORMATTING);
   
    doc1.save("data/AsposeMerged.doc", SaveFormat.DOC);
  }
View Full Code Here

public class AsposeWatermarks
{
  public static void main(String[] args) throws Exception
  {
        Document doc = new Document("data/document.doc");
        insertWatermarkText(doc, "CONFIDENTIAL");
        doc.save("data/AsposeWatermark.doc");
  }
View Full Code Here

public class AsposeUseControlCharacters
{
  public static void main(String[] args) throws Exception
  {
    // 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"
    text = text.replace(ControlChar.CR, ControlChar.CR_LF);
    System.out.println("Doc Text: " + text);
   
    doc.save("data/AsposeControlChars.doc", SaveFormat.DOC);
  }
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));
    pageSetup.setFooterDistance(ConvertUtil.inchToPoint(0.2));
   
    doc.save("data/AsposePageBorders.docx");
  }
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 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

// For more info please visit http://www.aspose.com/docs/display/wordsjava/Find+and+Replace+Overview
public class AsposeFindnReplace
{
  public static void main(String[] args) throws Exception
  {
    Document doc = new Document("data/replaceDoc.doc");
   
    // Replaces all 'sad' and 'mad' occurrences with 'bad'
    doc.getRange().replace("sad", "bad", false, true);
   
    // Replaces all 'sad' and 'mad' occurrences with 'bad'
    doc.getRange().replace(Pattern.compile("[s|m]ad"), "bad");
   
    doc.save("data/AsposeReplaced.doc", SaveFormat.DOC);
  }
View Full Code Here

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

    // This gets a live collection of all shape nodes in the document.
    NodeCollection shapeCollection = doc.getChildNodes(NodeType.SHAPE, true);

    // Since we will be adding/removing nodes, it is better to copy all collection
    // into a fixed size array, otherwise iterator will be invalidated.
    Node[] shapes = shapeCollection.toArray();

    for (Node node : shapes)
    {
        Shape shape = (Shape)node;
        // Filter out all shapes that we don't need.
        if (shape.getShapeType() == ShapeType.TEXT_BOX)
        {
            // Create a new shape that will replace the existing shape.
            Shape image = new Shape(doc, ShapeType.IMAGE);

            // Load the image into the new shape.
            image.getImageData().setImage("data/background.jpg");

            // Make new shape's position to match the old shape.
            image.setLeft(shape.getLeft());
            image.setTop(shape.getTop());
            image.setWidth(shape.getWidth());
            image.setHeight(shape.getHeight());
            image.setRelativeHorizontalPosition(shape.getRelativeHorizontalPosition());
            image.setRelativeVerticalPosition(shape.getRelativeVerticalPosition());
            image.setHorizontalAlignment(shape.getHorizontalAlignment());
            image.setVerticalAlignment(shape.getVerticalAlignment());
            image.setWrapType(shape.getWrapType());
            image.setWrapSide(shape.getWrapSide());

            // Insert new shape after the old shape and remove the old shape.
            shape.getParentNode().insertAfter(image, shape);
            shape.remove();
        }
    }

    doc.save("data/AsposeReplaceTextboxesWithImages.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

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.