com.aspose.words

Class LoadFormat

  • java.lang.Object
    • com.aspose.words.LoadFormat
public class LoadFormat 
extends java.lang.Object

Utility class containing constants. Indicates the format of the document that is to be loaded.

Example:

Shows how to open older binary DOC format for Word6.0/Word95 documents
LoadOptions loadOptions = new LoadOptions();
loadOptions.setLoadFormat(LoadFormat.DOC_PRE_WORD_60);

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

Example:

Explicitly loads a document as HTML without automatic file format detection.
LoadOptions loadOptions = new LoadOptions();
loadOptions.setLoadFormat(com.aspose.words.LoadFormat.HTML);
Document doc = new Document(getMyDir() + "Document.LoadFormat.html", loadOptions);

Example:

Shows how to insert the HTML contents from a web page into a new document.
// The url of the page to load
URL url = new URL("http://www.aspose.com/");

// The easiest way to load our document from the internet is make use of the URLConnection class.
URLConnection webClient = url.openConnection();

// Download the bytes from the location referenced by the URL.
InputStream inputStream = webClient.getInputStream();

// Convert the input stream to a byte array.
int pos;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((pos = inputStream.read()) != -1) bos.write(pos);

byte[] dataBytes = bos.toByteArray();

// Wrap the bytes representing the document in memory into a stream object.
ByteArrayInputStream byteStream = new ByteArrayInputStream(dataBytes);

// The baseUri property should be set to ensure any relative img paths are retrieved correctly.
LoadOptions options = new LoadOptions(LoadFormat.HTML, "", url.getPath());

// Load the HTML document from stream and pass the LoadOptions object.
Document doc = new Document(byteStream, options);

// Save the document to disk.
// The extension of the filename can be changed to save the document into other formats. e.g PDF, DOCX, ODT, RTF.
doc.save(getMyDir() + "\\Artifacts\\Document.HtmlPageFromWebpage.doc");

Example:

Check each file in the folder and move it to the appropriate subfolder.
// Loop through all found files.
for (File file : fileList)
{
    if (file.isDirectory())
        continue;

    // Extract and display the file name without the path.
    String nameOnly = file.getName();
    System.out.print(nameOnly);

    // Check the file format and move the file to the appropriate folder.
    String fileName = file.getPath();
    FileFormatInfo info = FileFormatUtil.detectFileFormat(fileName);

    // Display the document type.
    switch (info.getLoadFormat())
    {
        case LoadFormat.DOC:
            System.out.println("\tMicrosoft Word 97-2003 document.");
            break;
        case LoadFormat.DOT:
            System.out.println("\tMicrosoft Word 97-2003 template.");
            break;
        case LoadFormat.DOCX:
            System.out.println("\tOffice Open XML WordprocessingML Macro-Free Document.");
            break;
        case LoadFormat.DOCM:
            System.out.println("\tOffice Open XML WordprocessingML Macro-Enabled Document.");
            break;
        case LoadFormat.DOTX:
            System.out.println("\tOffice Open XML WordprocessingML Macro-Free Template.");
            break;
        case LoadFormat.DOTM:
            System.out.println("\tOffice Open XML WordprocessingML Macro-Enabled Template.");
            break;
        case LoadFormat.FLAT_OPC:
            System.out.println("\tFlat OPC document.");
            break;
        case LoadFormat.RTF:
            System.out.println("\tRTF format.");
            break;
        case LoadFormat.WORD_ML:
            System.out.println("\tMicrosoft Word 2003 WordprocessingML format.");
            break;
        case LoadFormat.HTML:
            System.out.println("\tHTML format.");
            break;
        case LoadFormat.MHTML:
            System.out.println("\tMHTML (Web archive) format.");
            break;
        case LoadFormat.ODT:
            System.out.println("\tOpenDocument Text.");
            break;
        case LoadFormat.OTT:
            System.out.println("\tOpenDocument Text Template.");
            break;
        case LoadFormat.DOC_PRE_WORD_60:
            System.out.println("\tMS Word 6 or Word 95 format.");
            break;
        case LoadFormat.UNKNOWN:
        default:
            System.out.println("\tUnknown format.");
            break;
    }

    // Now copy the document into the appropriate folder.
    if (info.isEncrypted())
    {
        System.out.println("\tAn encrypted document.");
        fileCopy(fileName, new File(encryptedDir, nameOnly).getPath());
    }
    else
    {
        switch (info.getLoadFormat())
        {
            case LoadFormat.DOC_PRE_WORD_60:
                fileCopy(fileName, new File(pre97Dir + nameOnly).getPath());
                break;
            case LoadFormat.UNKNOWN:
                fileCopy(fileName, new File(unknownDir + nameOnly).getPath());
                break;
            default:
                fileCopy(fileName, new File(supportedDir + nameOnly).getPath());
                break;
        }
    }
}

Field Summary
static final intAUTO = 0
Instructs Aspose.Words to recognize the format automatically.
static final intDOC = 10
Microsoft Word 97 - 2007 Document.
static final intDOT = 11
Microsoft Word 97 - 2007 Template.
static final intDOC_PRE_WORD_60 = 12
The document is in the Word 6 or Word 95 format. Aspose.Words does not currently support loading such documents.
static final intDOCX = 20
Office Open XML WordprocessingML Document (macro-free).
static final intDOCM = 21
Office Open XML WordprocessingML Macro-Enabled Document.
static final intDOTX = 22
Office Open XML WordprocessingML Template (macro-free).
static final intDOTM = 23
Office Open XML WordprocessingML Macro-Enabled Template.
static final intFLAT_OPC = 24
Office Open XML WordprocessingML stored in a flat XML file instead of a ZIP package.
static final intFLAT_OPC_MACRO_ENABLED = 25
Office Open XML WordprocessingML Macro-Enabled Document stored in a flat XML file instead of a ZIP package.
static final intFLAT_OPC_TEMPLATE = 26
Office Open XML WordprocessingML Template (macro-free) stored in a flat XML file instead of a ZIP package.
static final intFLAT_OPC_TEMPLATE_MACRO_ENABLED = 27
Office Open XML WordprocessingML Macro-Enabled Template stored in a flat XML file instead of a ZIP package.
static final intRTF = 30
RTF format.
static final intWORD_ML = 31
Microsoft Word 2003 WordprocessingML format.
static final intHTML = 50
HTML format.
static final intMHTML = 51
MHTML (Web archive) format.
static final intMOBI = 52
MOBI is an eBook format used by the MobiPocket Reader and Amazon Kindle Readers.
static final intODT = 60
ODF Text Document.
static final intOTT = 61
ODF Text Document Template.
static final intTEXT = 62
Plain Text
static final intUNKNOWN = 255
Unrecognized format, cannot be loaded by Aspose.Words.
 

    • Field Detail

      • AUTO = 0

        public static final int AUTO
        Instructs Aspose.Words to recognize the format automatically.
      • DOC = 10

        public static final int DOC
        Microsoft Word 97 - 2007 Document.
      • DOT = 11

        public static final int DOT
        Microsoft Word 97 - 2007 Template.
      • DOC_PRE_WORD_60 = 12

        public static final int DOC_PRE_WORD_60
        The document is in the Word 6 or Word 95 format. Aspose.Words does not currently support loading such documents.
      • DOCX = 20

        public static final int DOCX
        Office Open XML WordprocessingML Document (macro-free).
      • DOCM = 21

        public static final int DOCM
        Office Open XML WordprocessingML Macro-Enabled Document.
      • DOTX = 22

        public static final int DOTX
        Office Open XML WordprocessingML Template (macro-free).
      • DOTM = 23

        public static final int DOTM
        Office Open XML WordprocessingML Macro-Enabled Template.
      • FLAT_OPC = 24

        public static final int FLAT_OPC
        Office Open XML WordprocessingML stored in a flat XML file instead of a ZIP package.
      • FLAT_OPC_MACRO_ENABLED = 25

        public static final int FLAT_OPC_MACRO_ENABLED
        Office Open XML WordprocessingML Macro-Enabled Document stored in a flat XML file instead of a ZIP package.
      • FLAT_OPC_TEMPLATE = 26

        public static final int FLAT_OPC_TEMPLATE
        Office Open XML WordprocessingML Template (macro-free) stored in a flat XML file instead of a ZIP package.
      • FLAT_OPC_TEMPLATE_MACRO_ENABLED = 27

        public static final int FLAT_OPC_TEMPLATE_MACRO_ENABLED
        Office Open XML WordprocessingML Macro-Enabled Template stored in a flat XML file instead of a ZIP package.
      • RTF = 30

        public static final int RTF
        RTF format.
      • WORD_ML = 31

        public static final int WORD_ML
        Microsoft Word 2003 WordprocessingML format.
      • HTML = 50

        public static final int HTML
        HTML format.
      • MHTML = 51

        public static final int MHTML
        MHTML (Web archive) format.
      • MOBI = 52

        public static final int MOBI
        MOBI is an eBook format used by the MobiPocket Reader and Amazon Kindle Readers.
      • ODT = 60

        public static final int ODT
        ODF Text Document.
      • OTT = 61

        public static final int OTT
        ODF Text Document Template.
      • TEXT = 62

        public static final int TEXT
        Plain Text
      • UNKNOWN = 255

        public static final int UNKNOWN
        Unrecognized format, cannot be loaded by Aspose.Words.