public class LoadFormat
extends java.lang.Object
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));
| Modifier and Type | Field and Description |
|---|---|
static int |
AUTO
Instructs Aspose.Words to recognize the format automatically.
|
static int |
AZW_3
AZW3 format.
|
static int |
CHM
CHM (Compiled HTML Help) format.
|
static int |
DOC
Microsoft Word 95 or Word 97 - 2003 Document.
|
static int |
DOC_PRE_WORD_60
The document is in pre-Word 95 format.
|
static int |
DOCM
Office Open XML WordprocessingML Macro-Enabled Document.
|
static int |
DOCX
Office Open XML WordprocessingML Document (macro-free).
|
static int |
DOT
Microsoft Word 95 or Word 97 - 2003 Template.
|
static int |
DOTM
Office Open XML WordprocessingML Macro-Enabled Template.
|
static int |
DOTX
Office Open XML WordprocessingML Template (macro-free).
|
static int |
EPUB
EPUB format.
|
static int |
FLAT_OPC
Office Open XML WordprocessingML stored in a flat XML file instead of a ZIP package.
|
static int |
FLAT_OPC_MACRO_ENABLED
Office Open XML WordprocessingML Macro-Enabled Document stored in a flat XML file instead of a ZIP package.
|
static int |
FLAT_OPC_TEMPLATE
Office Open XML WordprocessingML Template (macro-free) stored in a flat XML file instead of a ZIP package.
|
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.
|
static int |
HTML
HTML format.
|
static int |
length |
static int |
MARKDOWN
Markdown text document.
|
static int |
MHTML
MHTML (Web archive) format.
|
static int |
MOBI
MOBI format.
|
static int |
MS_WORKS
Microsoft Works 8 Document.
|
static int |
ODT
ODF Text Document.
|
static int |
OTT
ODF Text Document Template.
|
static int |
PDF
Pdf document.
|
static int |
RTF
RTF format.
|
static int |
TEXT
Plain Text.
|
static int |
UNKNOWN
Unrecognized format, cannot be loaded by Aspose.Words.
|
static int |
WORD_ML
Microsoft Word 2003 WordprocessingML format.
|
static int |
XML
XML document.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
fromName(java.lang.String loadFormatName) |
static java.lang.String |
getName(int loadFormat) |
static int[] |
getValues() |
static java.lang.String |
toString(int loadFormat) |
public static int AUTO
public static int MS_WORKS
public static int DOC
public static int DOT
public static int DOC_PRE_WORD_60
public static int DOCX
public static int DOCM
public static int DOTX
public static int DOTM
public static int FLAT_OPC
public static int FLAT_OPC_MACRO_ENABLED
public static int FLAT_OPC_TEMPLATE
public static int FLAT_OPC_TEMPLATE_MACRO_ENABLED
public static int RTF
public static int WORD_ML
public static int HTML
public static int MHTML
public static int MOBI
public static int CHM
public static int AZW_3
public static int EPUB
public static int ODT
public static int OTT
public static int TEXT
public static int MARKDOWN
public static int PDF
public static int XML
public static int UNKNOWN
public static int length