LoadFormat

Inheritance: java.lang.Object

public class LoadFormat

Indicates the format of the document that is to be loaded.

Examples:

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");
 

Shows how to insert the HTML contents from a web page into a new document.


 URL url = new URL("https://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);

 doc.save(getArtifactsDir() + "Document.InsertHtmlFromWebPage.docx");
 

Shows how to use the FileFormatUtil methods to detect the format of a document.


 // Load a document from a file that is missing a file extension, and then detect its file format.
 FileInputStream docStream = new FileInputStream(getMyDir() + "Word document with missing file extension");

 FileFormatInfo info = FileFormatUtil.detectFileFormat(docStream);

 int loadFormat = info.getLoadFormat();

 Assert.assertEquals(LoadFormat.DOC, loadFormat);

 // Below are two methods of converting a LoadFormat to its corresponding SaveFormat.
 // 1 -  Get the file extension string for the LoadFormat, then get the corresponding SaveFormat from that string:
 String fileExtension = FileFormatUtil.loadFormatToExtension(loadFormat);

 int saveFormat = FileFormatUtil.extensionToSaveFormat(fileExtension);

 // 2 -  Convert the LoadFormat directly to its SaveFormat:
 saveFormat = FileFormatUtil.loadFormatToSaveFormat(loadFormat);

 // Load a document from the stream, and then save it to the automatically detected file extension.
 Document doc = new Document(docStream);

 Assert.assertEquals(".doc", FileFormatUtil.saveFormatToExtension(saveFormat));

 doc.save(getArtifactsDir() + "File.SaveToDetectedFileFormat" + FileFormatUtil.saveFormatToExtension(saveFormat));
 

Fields

FieldDescription
AUTOInstructs Aspose.Words to recognize the format automatically.
AZW_3AZW3 format.
CHMCHM (Compiled HTML Help) format.
DOCMicrosoft Word 95 or Word 97 - 2003 Document.
DOCMOffice Open XML WordprocessingML Macro-Enabled Document.
DOCXOffice Open XML WordprocessingML Document (macro-free).
DOC_PRE_WORD_60The document is in pre-Word 95 format.
DOTMicrosoft Word 95 or Word 97 - 2003 Template.
DOTMOffice Open XML WordprocessingML Macro-Enabled Template.
DOTXOffice Open XML WordprocessingML Template (macro-free).
EPUBEPUB format.
FLAT_OPCOffice Open XML WordprocessingML stored in a flat XML file instead of a ZIP package.
FLAT_OPC_MACRO_ENABLEDOffice Open XML WordprocessingML Macro-Enabled Document stored in a flat XML file instead of a ZIP package.
FLAT_OPC_TEMPLATEOffice Open XML WordprocessingML Template (macro-free) stored in a flat XML file instead of a ZIP package.
FLAT_OPC_TEMPLATE_MACRO_ENABLEDOffice Open XML WordprocessingML Macro-Enabled Template stored in a flat XML file instead of a ZIP package.
HTMLHTML format.
MARKDOWNMarkdown text document.
MHTMLMHTML (Web archive) format.
MOBIMOBI format.
ODTODF Text Document.
OTTODF Text Document Template.
PDFPdf document.
RTFRTF format.
TEXTPlain Text.
UNKNOWNUnrecognized format, cannot be loaded by Aspose.Words.
WORD_MLMicrosoft Word 2003 WordprocessingML format.
XMLXML document.
length

Methods

MethodDescription
fromName(String loadFormatName)
getName(int loadFormat)
getValues()
toString(int loadFormat)

AUTO

public static int AUTO

Instructs Aspose.Words to recognize the format automatically.

AZW_3

public static int AZW_3

AZW3 format. Used by Amazon Kindle readers.

CHM

public static int CHM

CHM (Compiled HTML Help) format.

DOC

public static int DOC

Microsoft Word 95 or Word 97 - 2003 Document.

DOCM

public static int DOCM

Office Open XML WordprocessingML Macro-Enabled Document.

DOCX

public static int DOCX

Office Open XML WordprocessingML Document (macro-free).

DOC_PRE_WORD_60

public static int DOC_PRE_WORD_60

The document is in pre-Word 95 format. Aspose.Words does not currently support loading such documents.

DOT

public static int DOT

Microsoft Word 95 or Word 97 - 2003 Template.

DOTM

public static int DOTM

Office Open XML WordprocessingML Macro-Enabled Template.

DOTX

public static int DOTX

Office Open XML WordprocessingML Template (macro-free).

EPUB

public static int EPUB

EPUB format.

FLAT_OPC

public static int FLAT_OPC

Office Open XML WordprocessingML stored in a flat XML file instead of a ZIP package.

FLAT_OPC_MACRO_ENABLED

public static 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

public static 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

public static int FLAT_OPC_TEMPLATE_MACRO_ENABLED

Office Open XML WordprocessingML Macro-Enabled Template stored in a flat XML file instead of a ZIP package.

HTML

public static int HTML

HTML format.

MARKDOWN

public static int MARKDOWN

Markdown text document.

MHTML

public static int MHTML

MHTML (Web archive) format.

MOBI

public static int MOBI

MOBI format. Used by MobiPocket reader and Amazon Kindle readers.

ODT

public static int ODT

ODF Text Document.

OTT

public static int OTT

ODF Text Document Template.

PDF

public static int PDF

Pdf document.

RTF

public static int RTF

RTF format.

TEXT

public static int TEXT

Plain Text.

UNKNOWN

public static int UNKNOWN

Unrecognized format, cannot be loaded by Aspose.Words.

WORD_ML

public static int WORD_ML

Microsoft Word 2003 WordprocessingML format.

XML

public static int XML

XML document.

length

public static int length

fromName(String loadFormatName)

public static int fromName(String loadFormatName)

Parameters:

ParameterTypeDescription
loadFormatNamejava.lang.String

Returns: int

getName(int loadFormat)

public static String getName(int loadFormat)

Parameters:

ParameterTypeDescription
loadFormatint

Returns: java.lang.String

getValues()

public static int[] getValues()

Returns: int[]

toString(int loadFormat)

public static String toString(int loadFormat)

Parameters:

ParameterTypeDescription
loadFormatint

Returns: java.lang.String