java.lang.Objectcom.aspose.words.CssSavingArgs
public class CssSavingArgs
By default, when Aspose.Words saves a document to HTML, it saves CSS information inline
(as a value of the style attribute on every element).
To save CSS into stream, use the To suppress saving CSS into a file and embedding to HTML document use the Example:
Document doc = new Document(getMyDir() + "Rendering.docx");
// Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we convert the document to HTML.
HtmlSaveOptions options = new HtmlSaveOptions();
// Set the "CssStylesheetType" property to "CssStyleSheetType.External" to
// accompany a saved HTML document with an external CSS stylesheet file.
options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
// Below are two ways of specifying directories and filenames for output CSS stylesheets.
// 1 - Use the "CssStyleSheetFileName" property to assign a filename to our stylesheet:
options.setCssStyleSheetFileName(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.css");
// 2 - Use a custom callback to name our stylesheet:
options.setCssSavingCallback(new CustomCssSavingCallback(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.css", true, false));
doc.save(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.html", options);
}
/// <summary>
/// Sets a custom filename, along with other parameters for an external CSS stylesheet.
/// </summary>
private static class CustomCssSavingCallback implements ICssSavingCallback {
public CustomCssSavingCallback(String cssDocFilename, boolean isExportNeeded, boolean keepCssStreamOpen) {
mCssTextFileName = cssDocFilename;
mIsExportNeeded = isExportNeeded;
mKeepCssStreamOpen = keepCssStreamOpen;
}
public void cssSaving(CssSavingArgs args) throws Exception {
// We can access the entire source document via the "Document" property.
Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.docx"));
args.setCssStream(new FileOutputStream(mCssTextFileName));
args.isExportNeeded(mIsExportNeeded);
args.setKeepCssStreamOpen(mKeepCssStreamOpen);
}
private final String mCssTextFileName;
private final boolean mIsExportNeeded;
private final boolean mKeepCssStreamOpen;
}
Property Getters/Setters Summary | ||
---|---|---|
java.io.OutputStream | getCssStream() | |
void | setCssStream(java.io.OutputStream value) | |
Allows to specify the stream where the CSS information will be saved to. | ||
Document | getDocument() | |
Gets the document object that is currently being saved. | ||
boolean | isExportNeeded() | |
void | isExportNeeded(boolean value) | |
Allows to specify whether the CSS will be exported to file and embedded to HTML document. Default is true .
When this property is false , the CSS information will not be saved to a CSS file and will not be embedded to HTML document.
|
||
boolean | getKeepCssStreamOpen() | |
void | setKeepCssStreamOpen(boolean value) | |
Specifies whether Aspose.Words should keep the stream open or close it after saving an CSS information. |
Property Getters/Setters Detail |
---|
getCssStream/setCssStream | |
public java.io.OutputStream getCssStream() / public void setCssStream(java.io.OutputStream value) |
This property allows you to save CSS information to a stream.
The default value is null
. This property doesn't suppress saving CSS information to a file or
embedding to HTML document. To suppress exporting CSS use the
Using
Example:
Shows how to work with CSS stylesheets that an HTML conversion creates.Document doc = new Document(getMyDir() + "Rendering.docx"); // Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method // to modify how we convert the document to HTML. HtmlSaveOptions options = new HtmlSaveOptions(); // Set the "CssStylesheetType" property to "CssStyleSheetType.External" to // accompany a saved HTML document with an external CSS stylesheet file. options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL); // Below are two ways of specifying directories and filenames for output CSS stylesheets. // 1 - Use the "CssStyleSheetFileName" property to assign a filename to our stylesheet: options.setCssStyleSheetFileName(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.css"); // 2 - Use a custom callback to name our stylesheet: options.setCssSavingCallback(new CustomCssSavingCallback(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.css", true, false)); doc.save(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.html", options); } /// <summary> /// Sets a custom filename, along with other parameters for an external CSS stylesheet. /// </summary> private static class CustomCssSavingCallback implements ICssSavingCallback { public CustomCssSavingCallback(String cssDocFilename, boolean isExportNeeded, boolean keepCssStreamOpen) { mCssTextFileName = cssDocFilename; mIsExportNeeded = isExportNeeded; mKeepCssStreamOpen = keepCssStreamOpen; } public void cssSaving(CssSavingArgs args) throws Exception { // We can access the entire source document via the "Document" property. Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.docx")); args.setCssStream(new FileOutputStream(mCssTextFileName)); args.isExportNeeded(mIsExportNeeded); args.setKeepCssStreamOpen(mKeepCssStreamOpen); } private final String mCssTextFileName; private final boolean mIsExportNeeded; private final boolean mKeepCssStreamOpen; }
getDocument | |
public Document getDocument() |
Example:
Shows how to work with CSS stylesheets that an HTML conversion creates.Document doc = new Document(getMyDir() + "Rendering.docx"); // Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method // to modify how we convert the document to HTML. HtmlSaveOptions options = new HtmlSaveOptions(); // Set the "CssStylesheetType" property to "CssStyleSheetType.External" to // accompany a saved HTML document with an external CSS stylesheet file. options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL); // Below are two ways of specifying directories and filenames for output CSS stylesheets. // 1 - Use the "CssStyleSheetFileName" property to assign a filename to our stylesheet: options.setCssStyleSheetFileName(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.css"); // 2 - Use a custom callback to name our stylesheet: options.setCssSavingCallback(new CustomCssSavingCallback(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.css", true, false)); doc.save(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.html", options); } /// <summary> /// Sets a custom filename, along with other parameters for an external CSS stylesheet. /// </summary> private static class CustomCssSavingCallback implements ICssSavingCallback { public CustomCssSavingCallback(String cssDocFilename, boolean isExportNeeded, boolean keepCssStreamOpen) { mCssTextFileName = cssDocFilename; mIsExportNeeded = isExportNeeded; mKeepCssStreamOpen = keepCssStreamOpen; } public void cssSaving(CssSavingArgs args) throws Exception { // We can access the entire source document via the "Document" property. Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.docx")); args.setCssStream(new FileOutputStream(mCssTextFileName)); args.isExportNeeded(mIsExportNeeded); args.setKeepCssStreamOpen(mKeepCssStreamOpen); } private final String mCssTextFileName; private final boolean mIsExportNeeded; private final boolean mKeepCssStreamOpen; }
isExportNeeded/isExportNeeded | |
public boolean isExportNeeded() / public void isExportNeeded(boolean value) |
true
.
When this property is false
, the CSS information will not be saved to a CSS file and will not be embedded to HTML document.
Example:
Shows how to work with CSS stylesheets that an HTML conversion creates.Document doc = new Document(getMyDir() + "Rendering.docx"); // Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method // to modify how we convert the document to HTML. HtmlSaveOptions options = new HtmlSaveOptions(); // Set the "CssStylesheetType" property to "CssStyleSheetType.External" to // accompany a saved HTML document with an external CSS stylesheet file. options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL); // Below are two ways of specifying directories and filenames for output CSS stylesheets. // 1 - Use the "CssStyleSheetFileName" property to assign a filename to our stylesheet: options.setCssStyleSheetFileName(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.css"); // 2 - Use a custom callback to name our stylesheet: options.setCssSavingCallback(new CustomCssSavingCallback(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.css", true, false)); doc.save(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.html", options); } /// <summary> /// Sets a custom filename, along with other parameters for an external CSS stylesheet. /// </summary> private static class CustomCssSavingCallback implements ICssSavingCallback { public CustomCssSavingCallback(String cssDocFilename, boolean isExportNeeded, boolean keepCssStreamOpen) { mCssTextFileName = cssDocFilename; mIsExportNeeded = isExportNeeded; mKeepCssStreamOpen = keepCssStreamOpen; } public void cssSaving(CssSavingArgs args) throws Exception { // We can access the entire source document via the "Document" property. Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.docx")); args.setCssStream(new FileOutputStream(mCssTextFileName)); args.isExportNeeded(mIsExportNeeded); args.setKeepCssStreamOpen(mKeepCssStreamOpen); } private final String mCssTextFileName; private final boolean mIsExportNeeded; private final boolean mKeepCssStreamOpen; }
getKeepCssStreamOpen/setKeepCssStreamOpen | |
public boolean getKeepCssStreamOpen() / public void setKeepCssStreamOpen(boolean value) |
Default is false
and Aspose.Words will close the stream you provided
in the true
to keep the stream open.
Example:
Shows how to work with CSS stylesheets that an HTML conversion creates.Document doc = new Document(getMyDir() + "Rendering.docx"); // Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method // to modify how we convert the document to HTML. HtmlSaveOptions options = new HtmlSaveOptions(); // Set the "CssStylesheetType" property to "CssStyleSheetType.External" to // accompany a saved HTML document with an external CSS stylesheet file. options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL); // Below are two ways of specifying directories and filenames for output CSS stylesheets. // 1 - Use the "CssStyleSheetFileName" property to assign a filename to our stylesheet: options.setCssStyleSheetFileName(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.css"); // 2 - Use a custom callback to name our stylesheet: options.setCssSavingCallback(new CustomCssSavingCallback(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.css", true, false)); doc.save(getArtifactsDir() + "SavingCallback.ExternalCssFilenames.html", options); } /// <summary> /// Sets a custom filename, along with other parameters for an external CSS stylesheet. /// </summary> private static class CustomCssSavingCallback implements ICssSavingCallback { public CustomCssSavingCallback(String cssDocFilename, boolean isExportNeeded, boolean keepCssStreamOpen) { mCssTextFileName = cssDocFilename; mIsExportNeeded = isExportNeeded; mKeepCssStreamOpen = keepCssStreamOpen; } public void cssSaving(CssSavingArgs args) throws Exception { // We can access the entire source document via the "Document" property. Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.docx")); args.setCssStream(new FileOutputStream(mCssTextFileName)); args.isExportNeeded(mIsExportNeeded); args.setKeepCssStreamOpen(mKeepCssStreamOpen); } private final String mCssTextFileName; private final boolean mIsExportNeeded; private final boolean mKeepCssStreamOpen; }