com.aspose.words
Class TxtLoadOptions

java.lang.Object
  extended by LoadOptions
      extended by com.aspose.words.TxtLoadOptions

public class TxtLoadOptions 
extends LoadOptions

Allows to specify additional options when loading LoadFormat.TEXT document into a Document object.

Constructor Summary
TxtLoadOptions()
           Initializes a new instance of this class with default values.
 
Property Getters/Setters Summary
java.lang.StringgetBaseUri()→ inherited from LoadOptions
voidsetBaseUri(java.lang.String value)
           Gets or sets the string that will be used to resolve relative URIs found in the document into absolute URIs when required. Can be null or empty string. Default is null.
booleangetConvertMetafilesToPng()→ inherited from LoadOptions
voidsetConvertMetafilesToPng(boolean value)
           Gets or sets whether to convert metafile (Wmf or Emf ) images to Png image format.
booleangetConvertShapeToOfficeMath()→ inherited from LoadOptions
voidsetConvertShapeToOfficeMath(boolean value)
           Gets or sets whether to convert shapes with EquationXML to Office Math objects.
booleangetDetectNumberingWithWhitespaces()
voidsetDetectNumberingWithWhitespaces(boolean value)
           Allows to specify how numbered list items are recognized when document is imported from plain text format. The default value is true.
intgetDocumentDirection()
voidsetDocumentDirection(int value)
           Gets or sets a document direction. The default value is DocumentDirection.LEFT_TO_RIGHT. The value of the property is DocumentDirection integer constant.
java.nio.charset.CharsetgetEncoding()→ inherited from LoadOptions
voidsetEncoding(java.nio.charset.Charset value)
           Gets or sets the encoding that will be used to load an HTML, TXT, or CHM document if the encoding is not specified inside the document. Can be null. Default is null.
FontSettingsgetFontSettings()→ inherited from LoadOptions
voidsetFontSettings(FontSettings value)
           Allows to specify document font settings.
LanguagePreferencesgetLanguagePreferences()→ inherited from LoadOptions
           Gets language preferences that will be used when document is loading.
intgetLeadingSpacesOptions()
voidsetLeadingSpacesOptions(int value)
           Gets or sets preferred option of a leading space handling. Default value is TxtLeadingSpacesOptions.CONVERT_TO_INDENT. The value of the property is TxtLeadingSpacesOptions integer constant.
intgetLoadFormat()→ inherited from LoadOptions
voidsetLoadFormat(int value)
           Specifies the format of the document to be loaded. Default is LoadFormat.AUTO. The value of the property is LoadFormat integer constant.
intgetMswVersion()→ inherited from LoadOptions
voidsetMswVersion(int value)
           Allows to specify that the document loading process should match a specific MS Word version. Default value is MsWordVersion.WORD_2007The value of the property is MsWordVersion integer constant.
java.lang.StringgetPassword()→ inherited from LoadOptions
voidsetPassword(java.lang.String value)
           Gets or sets the password for opening an encrypted document. Can be null or empty string. Default is null.
booleangetPreserveIncludePictureField()→ inherited from LoadOptions
voidsetPreserveIncludePictureField(boolean value)
           Gets or sets whether to preserve the INCLUDEPICTURE field when reading Microsoft Word formats. The default value is false.
IResourceLoadingCallbackgetResourceLoadingCallback()→ inherited from LoadOptions
voidsetResourceLoadingCallback(IResourceLoadingCallback value)
           Allows to control how external resources (images, style sheets) are loaded when a document is imported from HTML, MHTML.
java.lang.StringgetTempFolder()→ inherited from LoadOptions
voidsetTempFolder(java.lang.String value)
           Allows to use temporary files when reading document. By default this property is null and no temporary files are used.
intgetTrailingSpacesOptions()
voidsetTrailingSpacesOptions(int value)
           Gets or sets preferred option of a trailing space handling. Default value is TxtTrailingSpacesOptions.TRIM. The value of the property is TxtTrailingSpacesOptions integer constant.
booleangetUpdateDirtyFields()→ inherited from LoadOptions
voidsetUpdateDirtyFields(boolean value)
           Specifies whether to update the fields with the dirty attribute.
IWarningCallbackgetWarningCallback()→ inherited from LoadOptions
voidsetWarningCallback(IWarningCallback value)
           Called during a load operation, when an issue is detected that might result in data or formatting fidelity loss.
 

Constructor Detail

TxtLoadOptions

public TxtLoadOptions()
Initializes a new instance of this class with default values.

Property Getters/Setters Detail

getBaseUri/setBaseUri

→ inherited from LoadOptions
public java.lang.String getBaseUri() / public void setBaseUri(java.lang.String value)
Gets or sets the string that will be used to resolve relative URIs found in the document into absolute URIs when required. Can be null or empty string. Default is null.

This property is used to resolve relative URIs into absolute in the following cases:

  1. When loading an HTML document from a stream and the document contains images with relative URIs and does not have a base URI specified in the BASE HTML element.
  2. When saving a document to PDF and other formats, to retrieve images linked using relative URIs so the images can be saved into the output document.

Example:

Shows how to open an HTML document with images from a stream using a base URI.
InputStream stream = new FileInputStream(getMyDir() + "Document.html");
try /*JAVA: was using*/ {
    // Pass the URI of the base folder while loading it
    // so that any images with relative URIs in the HTML document can be found.
    LoadOptions loadOptions = new LoadOptions();
    loadOptions.setBaseUri(getImageDir());

    Document doc = new Document(stream, loadOptions);

    // Verify that the first shape of the document contains a valid image.
    Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);

    Assert.assertTrue(shape.isImage());
    Assert.assertNotNull(shape.getImageData().getImageBytes());
    Assert.assertEquals(32.0, ConvertUtil.pointToPixel(shape.getWidth()), 0.01);
    Assert.assertEquals(32.0, ConvertUtil.pointToPixel(shape.getHeight()), 0.01);
} finally {
    if (stream != null) stream.close();
}

getConvertMetafilesToPng/setConvertMetafilesToPng

→ inherited from LoadOptions
public boolean getConvertMetafilesToPng() / public void setConvertMetafilesToPng(boolean value)
Gets or sets whether to convert metafile (Wmf or Emf ) images to Png image format. Metafiles (Wmf or Emf ) is an uncompressed image format and sometimes requires to much RAM to hold and process document. This option allows to convert all metafile images to Png on document loading. Please note - conversion vector graphics to raster decreases quality of the images.

getConvertShapeToOfficeMath/setConvertShapeToOfficeMath

→ inherited from LoadOptions
public boolean getConvertShapeToOfficeMath() / public void setConvertShapeToOfficeMath(boolean value)
Gets or sets whether to convert shapes with EquationXML to Office Math objects.

getDetectNumberingWithWhitespaces/setDetectNumberingWithWhitespaces

public boolean getDetectNumberingWithWhitespaces() / public void setDetectNumberingWithWhitespaces(boolean value)
Allows to specify how numbered list items are recognized when document is imported from plain text format. The default value is true.

If this option is set to false, lists recognition algorithm detects list paragraphs, when list numbers ends with either dot, right bracket or bullet symbols (such as "•", "*", "-" or "o").

If this option is set to true, whitespaces are also used as list number delimeters: list recognition algorithm for Arabic style numbering (1., 1.1.2.) uses both whitespaces and dot (".") symbols.


getDocumentDirection/setDocumentDirection

public int getDocumentDirection() / public void setDocumentDirection(int value)
Gets or sets a document direction. The default value is DocumentDirection.LEFT_TO_RIGHT. The value of the property is DocumentDirection integer constant.

Example:

Shows how to detect document direction automatically.
// Create a LoadOptions object and configure it to detect text direction automatically upon loading
TxtLoadOptions loadOptions = new TxtLoadOptions();
loadOptions.setDocumentDirection(DocumentDirection.AUTO);

// Text like Hebrew/Arabic will be automatically detected as RTL
Document doc = new Document(getMyDir() + "Hebrew text.txt", loadOptions);

Assert.assertTrue(doc.getFirstSection().getBody().getFirstParagraph().getParagraphFormat().getBidi());

doc = new Document(getMyDir() + "English text.txt", loadOptions);

Assert.assertFalse(doc.getFirstSection().getBody().getFirstParagraph().getParagraphFormat().getBidi());

getEncoding/setEncoding

→ inherited from LoadOptions
public java.nio.charset.Charset getEncoding() / public void setEncoding(java.nio.charset.Charset value)
Gets or sets the encoding that will be used to load an HTML, TXT, or CHM document if the encoding is not specified inside the document. Can be null. Default is null.

This property is used only when loading HTML, TXT, or CHM documents.

If encoding is not specified inside the document and this property is null, then the system will try to automatically detect the encoding.


getFontSettings/setFontSettings

→ inherited from LoadOptions
public FontSettings getFontSettings() / public void setFontSettings(FontSettings value)
Allows to specify document font settings.

When loading some formats, Aspose.Words may require to resolve the fonts. For example, when loading HTML documents Aspose.Words may resolve the fonts to perform font fallback.

If set to null, default static font settings FontSettings.DefaultInstance will be used.

The default value is null.


getLanguagePreferences

→ inherited from LoadOptions
public LanguagePreferences getLanguagePreferences()
Gets language preferences that will be used when document is loading.

getLeadingSpacesOptions/setLeadingSpacesOptions

public int getLeadingSpacesOptions() / public void setLeadingSpacesOptions(int value)
Gets or sets preferred option of a leading space handling. Default value is TxtLeadingSpacesOptions.CONVERT_TO_INDENT. The value of the property is TxtLeadingSpacesOptions integer constant.

getLoadFormat/setLoadFormat

→ inherited from LoadOptions
public int getLoadFormat() / public void setLoadFormat(int value)
Specifies the format of the document to be loaded. Default is LoadFormat.AUTO. The value of the property is LoadFormat integer constant.

It is recommended that you specify the LoadFormat.AUTO value and let Aspose.Words detect the file format automatically. If you know the format of the document you are about to load, you can specify the format explicitly and this will slightly reduce the loading time by the overhead associated with auto detecting the format. If you specify an explicit load format and it will turn out to be wrong, the auto detection will be invoked and a second attempt to load the file will be made.

Example:

Shows how to specify a base URI when opening an html document.
// Suppose we want to load an .html document that contains an image linked by a relative URI
// while the image is in a different location. In that case, we will need to resolve the relative URI into an absolute one.
// We can provide a base URI using an HtmlLoadOptions object. 
HtmlLoadOptions loadOptions = new HtmlLoadOptions(LoadFormat.HTML, "", getImageDir());

Assert.assertEquals(LoadFormat.HTML, loadOptions.getLoadFormat());

Document doc = new Document(getMyDir() + "Missing image.html", loadOptions);

// While the image was broken in the input .html, our custom base URI helped us repair the link.
Shape imageShape = (Shape) doc.getChildNodes(NodeType.SHAPE, true).get(0);
Assert.assertTrue(imageShape.isImage());

// This output document will display the image that was missing.
doc.save(getArtifactsDir() + "HtmlLoadOptions.BaseUri.docx");

getMswVersion/setMswVersion

→ inherited from LoadOptions
public int getMswVersion() / public void setMswVersion(int value)
Allows to specify that the document loading process should match a specific MS Word version. Default value is MsWordVersion.WORD_2007The value of the property is MsWordVersion integer constant. Different Word versions may handle certain aspects of document content and formatting slightly differently during the loading process, which may result in minor differences in Document Object Model.

getPassword/setPassword

→ inherited from LoadOptions
public java.lang.String getPassword() / public void setPassword(java.lang.String value)
Gets or sets the password for opening an encrypted document. Can be null or empty string. Default is null.

You need to know the password to open an encrypted document. If the document is not encrypted, set this to null or empty string.

Example:

Shows how to sign encrypted document file.
// Create an X.509 certificate from a PKCS#12 store, which should contain a private key.
CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");

// Create a comment, date, and decryption password which will be applied with our new digital signature.
SignOptions signOptions = new SignOptions();
{
    signOptions.setComments("Comment");
    signOptions.setSignTime(new Date());
    signOptions.setDecryptionPassword("docPassword");
}

// Set a local system filename for the unsigned input document, and an output filename for its new digitally signed copy.
String inputFileName = getMyDir() + "Encrypted.docx";
String outputFileName = getArtifactsDir() + "DigitalSignatureUtil.DecryptionPassword.docx";

DigitalSignatureUtil.sign(inputFileName, outputFileName, certificateHolder, signOptions);

getPreserveIncludePictureField/setPreserveIncludePictureField

→ inherited from LoadOptions
public boolean getPreserveIncludePictureField() / public void setPreserveIncludePictureField(boolean value)
Gets or sets whether to preserve the INCLUDEPICTURE field when reading Microsoft Word formats. The default value is false.

By default, the INCLUDEPICTURE field is converted into a shape object. You can override that if you need the field to be preserved, for example, if you wish to update it programmatically. Note however that this approach is not common for Aspose.Words. Use it on your own risk.

One of the possible use cases may be using a MERGEFIELD as a child field to dynamically change the source path of the picture. In this case you need the INCLUDEPICTURE to be preserved in the model.


getResourceLoadingCallback/setResourceLoadingCallback

→ inherited from LoadOptions
public IResourceLoadingCallback getResourceLoadingCallback() / public void setResourceLoadingCallback(IResourceLoadingCallback value)
Allows to control how external resources (images, style sheets) are loaded when a document is imported from HTML, MHTML.

getTempFolder/setTempFolder

→ inherited from LoadOptions
public java.lang.String getTempFolder() / public void setTempFolder(java.lang.String value)
Allows to use temporary files when reading document. By default this property is null and no temporary files are used.

The folder must exist and be writable, otherwise an exception will be thrown.

Aspose.Words automatically deletes all temporary files when reading is complete.

Example:

Shows how to load a document using temporary files.
// Note that such an approach can reduce memory usage but degrades speed.
LoadOptions loadOptions = new LoadOptions();
loadOptions.setTempFolder("C:\\TempFolder\\");

// Ensure that the directory exists and load.
new File(loadOptions.getTempFolder()).mkdir();

Document doc = new Document(getMyDir() + "Document.docx", loadOptions);

getTrailingSpacesOptions/setTrailingSpacesOptions

public int getTrailingSpacesOptions() / public void setTrailingSpacesOptions(int value)
Gets or sets preferred option of a trailing space handling. Default value is TxtTrailingSpacesOptions.TRIM. The value of the property is TxtTrailingSpacesOptions integer constant.

getUpdateDirtyFields/setUpdateDirtyFields

→ inherited from LoadOptions
public boolean getUpdateDirtyFields() / public void setUpdateDirtyFields(boolean value)
Specifies whether to update the fields with the dirty attribute.

Example:

Shows how to use special property for updating field result.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Give the document's built-in "Author" property value, and then display it with a field.
doc.getBuiltInDocumentProperties().setAuthor("John Doe");
FieldAuthor field = (FieldAuthor) builder.insertField(FieldType.FIELD_AUTHOR, true);

Assert.assertFalse(field.isDirty());
Assert.assertEquals("John Doe", field.getResult());

// Update the property. The field still displays the old value.
doc.getBuiltInDocumentProperties().setAuthor("John & Jane Doe");

Assert.assertEquals("John Doe", field.getResult());

// Since the field's value is out of date, we can mark it as "dirty".
// This value will stay out of date until we update the field manually with the Field.Update() method.
field.isDirty(true);

OutputStream docStream = new FileOutputStream(getArtifactsDir() + "Filed.UpdateDirtyFields.docx");
try {
    // If we save without calling an update method,
    // the field will keep displaying the out of date value in the output document.
    doc.save(docStream, SaveFormat.DOCX);

    // The LoadOptions object has an option to update all fields
    // marked as "dirty" when loading the document.
    LoadOptions options = new LoadOptions();
    options.setUpdateDirtyFields(updateDirtyFields);

    doc = new Document(String.valueOf(docStream), options);

    Assert.assertEquals("John & Jane Doe", doc.getBuiltInDocumentProperties().getAuthor());

    field = (FieldAuthor) doc.getRange().getFields().get(0);

    // Updating dirty fields like this automatically set their "IsDirty" flag to false.
    if (updateDirtyFields) {
        Assert.assertEquals("John & Jane Doe", field.getResult());
        Assert.assertFalse(field.isDirty());
    } else {
        Assert.assertEquals("John Doe", field.getResult());
        Assert.assertTrue(field.isDirty());
    }
} finally {
    if (docStream != null) docStream.close();
}

getWarningCallback/setWarningCallback

→ inherited from LoadOptions
public IWarningCallback getWarningCallback() / public void setWarningCallback(IWarningCallback value)
Called during a load operation, when an issue is detected that might result in data or formatting fidelity loss.

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