com.aspose.words
Class ImportFormatOptions

java.lang.Object
    extended by com.aspose.words.ImportFormatOptions

public class ImportFormatOptions 
extends java.lang.Object

Allows to specify various import options to format output.

Example:

Shows how to resolve styles behavior while inserting documents.
Document destDoc = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.DestinationDocument.docx");
Document sourceDoc1 = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.SourceDocument01.docx");
Document sourceDoc2 = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.SourceDocument02.docx");

DocumentBuilder builder = new DocumentBuilder(destDoc);

builder.moveToDocumentEnd();
builder.insertBreak(BreakType.PAGE_BREAK);
builder.moveToDocumentEnd();

ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.setSmartStyleBehavior(true);

// When SmartStyleBehavior is enabled,
// a source style will be expanded into a direct attributes inside a destination document,
// if KeepSourceFormatting importing mode is used.
builder.insertDocument(sourceDoc1, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions);

builder.moveToDocumentEnd();
builder.insertBreak(BreakType.PAGE_BREAK);

// When SmartStyleBehavior is disabled,
// a source style will be expanded only if it is numbered.
// Existing destination attributes will not be overridden, including lists.
builder.insertDocument(sourceDoc2, ImportFormatMode.USE_DESTINATION_STYLES);

destDoc.save(getArtifactsDir() + "DocumentBuilder.SmartStyleBehavior.ResultDocument.docx");

Constructor Summary
ImportFormatOptions()
          
 
Property Getters/Setters Summary
booleangetIgnoreTextBoxes()
voidsetIgnoreTextBoxes(boolean value)
           Gets or sets a boolean value that indicates whether to ignore formatting in the text boxes of the source destination during the import. Default value is true.
booleangetKeepSourceNumbering()
voidsetKeepSourceNumbering(boolean value)
           Gets or sets a boolean value that specifies how the numbering will be imported when it clashes in source and destination documents. The default value is false.
booleangetSmartStyleBehavior()
voidsetSmartStyleBehavior(boolean value)
           Gets or sets a boolean value that specifies how styles will be imported when they have equal names in source and destination documents. The default value is false.
 

Constructor Detail

ImportFormatOptions

public ImportFormatOptions()

Property Getters/Setters Detail

getIgnoreTextBoxes/setIgnoreTextBoxes

public boolean getIgnoreTextBoxes() / public void setIgnoreTextBoxes(boolean value)
Gets or sets a boolean value that indicates whether to ignore formatting in the text boxes of the source destination during the import. Default value is true.

Example:

Shows how to manage formatting in the text boxes of the source destination during the import.
Document dstDoc = new Document(getMyDir() + "DocumentBuilder.IgnoreTextBoxes.DestinationDocument.docx");
Document srcDoc = new Document(getMyDir() + "DocumentBuilder.IgnoreTextBoxes.SourceDocument.docx");

ImportFormatOptions importFormatOptions = new ImportFormatOptions();
// Keep the source text boxes formatting when importing
importFormatOptions.setIgnoreTextBoxes(false);

NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions);

ParagraphCollection paragraphs = srcDoc.getFirstSection().getBody().getParagraphs();
for (int i = 0; i < paragraphs.getCount(); i++) {
    Paragraph srcPara = paragraphs.get(i);
    Node importedNode = importer.importNode(srcPara, true);
    dstDoc.getFirstSection().getBody().appendChild(importedNode);
}

dstDoc.save(getArtifactsDir() + "DocumentBuilder.IgnoreTextBoxes.ResultDocument.docx");

getKeepSourceNumbering/setKeepSourceNumbering

public boolean getKeepSourceNumbering() / public void setKeepSourceNumbering(boolean value)
Gets or sets a boolean value that specifies how the numbering will be imported when it clashes in source and destination documents. The default value is false.

Example:

Shows how the numbering will be imported when it clashes in source and destination documents.
Document dstDoc = new Document(getMyDir() + "DocumentBuilder.KeepSourceNumbering.DestinationDocument.docx");
Document srcDoc = new Document(getMyDir() + "DocumentBuilder.KeepSourceNumbering.SourceDocument.docx");

ImportFormatOptions importFormatOptions = new ImportFormatOptions();
// Keep source list formatting when importing numbered paragraphs
importFormatOptions.setKeepSourceNumbering(true);

NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions);

ParagraphCollection paragraphs = srcDoc.getFirstSection().getBody().getParagraphs();
for (int i = 0; i < paragraphs.getCount(); i++) {
    Paragraph srcPara = paragraphs.get(i);
    Node importedNode = importer.importNode(srcPara, true);
    dstDoc.getFirstSection().getBody().appendChild(importedNode);
}

dstDoc.save(getArtifactsDir() + "DocumentBuilder.KeepSourceNumbering.ResultDocument.docx");

getSmartStyleBehavior/setSmartStyleBehavior

public boolean getSmartStyleBehavior() / public void setSmartStyleBehavior(boolean value)
Gets or sets a boolean value that specifies how styles will be imported when they have equal names in source and destination documents. The default value is false.

When this option is enabled, the source style will be expanded into a direct attributes inside a destination document, if ImportFormatMode.KEEP_SOURCE_FORMATTING importing mode is used.

When this option is disabled, the source style will be expanded only if it is numbered. Existing destination attributes will not be overridden, including lists.

Example:

Shows how to resolve styles behavior while inserting documents.
Document destDoc = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.DestinationDocument.docx");
Document sourceDoc1 = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.SourceDocument01.docx");
Document sourceDoc2 = new Document(getMyDir() + "DocumentBuilder.SmartStyleBehavior.SourceDocument02.docx");

DocumentBuilder builder = new DocumentBuilder(destDoc);

builder.moveToDocumentEnd();
builder.insertBreak(BreakType.PAGE_BREAK);
builder.moveToDocumentEnd();

ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.setSmartStyleBehavior(true);

// When SmartStyleBehavior is enabled,
// a source style will be expanded into a direct attributes inside a destination document,
// if KeepSourceFormatting importing mode is used.
builder.insertDocument(sourceDoc1, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions);

builder.moveToDocumentEnd();
builder.insertBreak(BreakType.PAGE_BREAK);

// When SmartStyleBehavior is disabled,
// a source style will be expanded only if it is numbered.
// Existing destination attributes will not be overridden, including lists.
builder.insertDocument(sourceDoc2, ImportFormatMode.USE_DESTINATION_STYLES);

destDoc.save(getArtifactsDir() + "DocumentBuilder.SmartStyleBehavior.ResultDocument.docx");

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.