HtmlViewOptions
Inheritance: java.lang.Object, com.groupdocs.viewer.options.BaseViewOptions, com.groupdocs.viewer.options.ViewOptions
public class HtmlViewOptions extends ViewOptions
Provides options for rendering documents into HTML format.
The HtmlViewOptions class encapsulates additional settings and parameters that can be used to control the rendering of documents into HTML format in the GroupDocs.Viewer component.
For details, see the topic and its children.
Example usage:
HtmlViewOptions options = HtmlViewOptions.forEmbeddedResources();
options.setExcludeFonts(true);
options.setFontsToExclude(Arrays.asList("font-name"));
try (Viewer viewer = new Viewer("document.docx")) {
viewer.view(options);
// Use the viewer object for further operations
}
Fields
Field | Description |
---|---|
CREATE_PAGE_STREAM | |
FILE_PATH_FORMAT |
Methods
Method | Description |
---|---|
getImageMaxWidth() | Returns the maximum width of an output image in pixels. |
setImageMaxWidth(int imageMaxWidth) | Sets the maximum width of an output image in pixels. |
getImageMaxHeight() | Gets the maximum height of an output image in pixels. |
setImageMaxHeight(int imageMaxHeight) | Sets the maximum height of an output image in pixels. |
getImageWidth() | Gets the width of the output image in pixels. |
setImageWidth(int imageWidth) | Sets the width of the output image in pixels. |
getImageHeight() | Gets the height of the output image in pixels when converting a single image to HTML. |
setImageHeight(int imageHeight) | Sets the height of the output image in pixels when converting a single image to HTML. |
forEmbeddedResources(CreatePageStream createPageStream) | Initializes a new instance of the HtmlViewOptions class for rendering into HTML with embedded resources. |
forEmbeddedResources(CreatePageStream createPageStream, ReleasePageStream releasePageStream) | Initializes a new instance of the HtmlViewOptions class for rendering into HTML with embedded resources. |
forEmbeddedResources(PageStreamFactory pageStreamFactory) | Initializes a new instance of the HtmlViewOptions class for rendering into HTML with embedded resources. |
forEmbeddedResources() | Initializes a new instance of the HtmlViewOptions class. |
forEmbeddedResources(String filePathFormat) | Initializes a new instance of the HtmlViewOptions class. |
forEmbeddedResources(Path filePathFormat) | Initializes a new instance of the HtmlViewOptions class. |
forExternalResources(CreatePageStream createPageStream, CreateResourceStream createResourceStream, CreateResourceUrl createResourceUrl) | Initializes a new instance of the HtmlViewOptions class for rendering into HTML with external resources. |
forExternalResources(CreatePageStream createPageStream, CreateResourceStream createResourceStream, CreateResourceUrl createResourceUrl, ReleasePageStream releasePageStream, ReleaseResourceStream releaseResourceStream) | Initializes a new instance of the HtmlViewOptions class for rendering into HTML with external resources. |
forExternalResources(PageStreamFactory pageStreamFactory, ResourceStreamFactory resourceStreamFactory) | Initializes a new instance of the HtmlViewOptions class for rendering into HTML with external resources. |
forExternalResources() | Initializes new instance of HtmlViewOptions class. |
forExternalResources(String filePathFormat, String resourceFilePathFormat, String resourceUrlFormat) | Initializes a new instance of the HtmlViewOptions class. |
isRenderResponsive() | Determines whether responsive rendering is enabled. |
setRenderResponsive(boolean value) | Sets whether responsive rendering is enabled. |
isMinify() | Checks if HTML content and HTML resources minification is enabled. |
setMinify(boolean value) | Sets whether HTML content and HTML resources minification is enabled. |
setRenderToSinglePage(boolean renderSinglePage) | Enables rendering an entire document to one HTML file. |
isRenderToSinglePage() | Enables rendering an entire document to one HTML file. |
isExcludeFonts() | Determines whether to exclude fonts from the HTML document. |
setExcludeFonts(boolean value) | Sets whether to exclude fonts from the HTML document. |
getFontsToExclude() | Retrieves the list of font names to exclude from the HTML document. |
setFontsToExclude(List |
Sets the list of font names to exclude from the HTML document. |
isForPrinting() | Checks if the output HTML should be optimized for printing. |
setForPrinting(boolean value) | Sets whether the output HTML should be optimized for printing. |
getDocumentSavingCallback() | Retrieves the callback used to estimate the saving progress of a Words or Email document. |
setDocumentSavingCallback(IDocumentSavingCallback documentSavingCallback) | Sets the callback used to estimate the saving progress of a Words or Email document. |
CREATE_PAGE_STREAM
public static final String CREATE_PAGE_STREAM
FILE_PATH_FORMAT
public static final String FILE_PATH_FORMAT
getImageMaxWidth()
public int getImageMaxWidth()
Returns the maximum width of an output image in pixels.
Note: This value is used when converting a single image to HTML. For details and code example, see the documentation.
Returns: int - the maximum width of an output image.
setImageMaxWidth(int imageMaxWidth)
public void setImageMaxWidth(int imageMaxWidth)
Sets the maximum width of an output image in pixels.
Note: This value is used when converting a single image to HTML. For details and code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
imageMaxWidth | int | The maximum width of an output image. |
getImageMaxHeight()
public int getImageMaxHeight()
Gets the maximum height of an output image in pixels.
Note: This option applies when converting a single image to HTML. It specifies the maximum height of the output image. For details and code example, see the documentation.
Returns: int - the maximum height of an output image.
setImageMaxHeight(int imageMaxHeight)
public void setImageMaxHeight(int imageMaxHeight)
Sets the maximum height of an output image in pixels.
Note: This option applies when converting a single image to HTML. It specifies the maximum height of the output image. For details and code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
imageMaxHeight | int | The maximum height of an output image. |
getImageWidth()
public int getImageWidth()
Gets the width of the output image in pixels.
Note: This value is applicable only when converting a single image to HTML. For details and code example, see the documentation.
Returns: int - the width of the output image.
setImageWidth(int imageWidth)
public void setImageWidth(int imageWidth)
Sets the width of the output image in pixels.
Note: This value is applicable only when converting a single image to HTML. For details and code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
imageWidth | int | The width of the output image. |
getImageHeight()
public int getImageHeight()
Gets the height of the output image in pixels when converting a single image to HTML.
For details and code example, see the documentation.
Returns: int - the height of the output image in pixels.
setImageHeight(int imageHeight)
public void setImageHeight(int imageHeight)
Sets the height of the output image in pixels when converting a single image to HTML.
For details and code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
imageHeight | int | The height of the output image in pixels. |
forEmbeddedResources(CreatePageStream createPageStream)
public static HtmlViewOptions forEmbeddedResources(CreatePageStream createPageStream)
Initializes a new instance of the HtmlViewOptions class for rendering into HTML with embedded resources.
Note: The method takes a CreatePageStream parameter, which is a method used to instantiate a stream for writing output page data. For the code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
createPageStream | CreatePageStream | The method that instantiates a stream used to write output page data. |
Returns: HtmlViewOptions - a new instance of the HtmlViewOptions class for rendering into HTML with embedded resources.
forEmbeddedResources(CreatePageStream createPageStream, ReleasePageStream releasePageStream)
public static HtmlViewOptions forEmbeddedResources(CreatePageStream createPageStream, ReleasePageStream releasePageStream)
Initializes a new instance of the HtmlViewOptions class for rendering into HTML with embedded resources.
For the code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
createPageStream | CreatePageStream | The method that instantiates a stream used to write output page data. |
releasePageStream | ReleasePageStream | The method that releases the stream created by the method assigned to the createPageStream parameter. |
Returns: HtmlViewOptions - a new instance of the HtmlViewOptions class for rendering into HTML with embedded resources.
forEmbeddedResources(PageStreamFactory pageStreamFactory)
public static HtmlViewOptions forEmbeddedResources(PageStreamFactory pageStreamFactory)
Initializes a new instance of the HtmlViewOptions class for rendering into HTML with embedded resources.
For the code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
pageStreamFactory | PageStreamFactory | The factory that implements methods for creating and releasing the output page stream. |
Returns: HtmlViewOptions - a new instance of the HtmlViewOptions class for rendering into HTML with embedded resources.
forEmbeddedResources()
public static HtmlViewOptions forEmbeddedResources()
Initializes a new instance of the HtmlViewOptions class.
For the code example, see the documentation.
Returns: HtmlViewOptions - a new instance of the HtmlViewOptions class.
forEmbeddedResources(String filePathFormat)
public static HtmlViewOptions forEmbeddedResources(String filePathFormat)
Initializes a new instance of the HtmlViewOptions class.
For the code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
filePathFormat | java.lang.String | The file path format, e.g., ‘page_{0}.html’. |
Returns: HtmlViewOptions - a new instance of the HtmlViewOptions class.
forEmbeddedResources(Path filePathFormat)
public static HtmlViewOptions forEmbeddedResources(Path filePathFormat)
Initializes a new instance of the HtmlViewOptions class.
For the code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
filePathFormat | java.nio.file.Path | The file path format, e.g., ‘page_{0}.html’. |
Returns: HtmlViewOptions - a new instance of the HtmlViewOptions class.
forExternalResources(CreatePageStream createPageStream, CreateResourceStream createResourceStream, CreateResourceUrl createResourceUrl)
public static HtmlViewOptions forExternalResources(CreatePageStream createPageStream, CreateResourceStream createResourceStream, CreateResourceUrl createResourceUrl)
Initializes a new instance of the HtmlViewOptions class for rendering into HTML with external resources.
Note: This method should be used when rendering HTML with external resources, such as CSS and JavaScript files. For the code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
createPageStream | CreatePageStream | The method that instantiates the stream used to write output page data. |
createResourceStream | CreateResourceStream | The method that releases the stream created by the createPageStream method. |
createResourceUrl | CreateResourceUrl | The method that creates the URL for the HTML resource. |
Returns: HtmlViewOptions - a new instance of the HtmlViewOptions class for rendering into HTML with external resources.
forExternalResources(CreatePageStream createPageStream, CreateResourceStream createResourceStream, CreateResourceUrl createResourceUrl, ReleasePageStream releasePageStream, ReleaseResourceStream releaseResourceStream)
public static HtmlViewOptions forExternalResources(CreatePageStream createPageStream, CreateResourceStream createResourceStream, CreateResourceUrl createResourceUrl, ReleasePageStream releasePageStream, ReleaseResourceStream releaseResourceStream)
Initializes a new instance of the HtmlViewOptions class for rendering into HTML with external resources.
For the code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
createPageStream | CreatePageStream | The method that instantiates the stream used to write output page data. |
createResourceStream | CreateResourceStream | The method that instantiates the stream used to write output HTML resource data. |
createResourceUrl | CreateResourceUrl | The method that creates the URL for the HTML resource. |
releasePageStream | ReleasePageStream | The method that releases the stream created by the createPageStream method. |
releaseResourceStream | ReleaseResourceStream | The method that releases the stream created by the createResourceStream method. |
Returns: HtmlViewOptions - a new instance of the HtmlViewOptions class for rendering into HTML with external resources.
forExternalResources(PageStreamFactory pageStreamFactory, ResourceStreamFactory resourceStreamFactory)
public static HtmlViewOptions forExternalResources(PageStreamFactory pageStreamFactory, ResourceStreamFactory resourceStreamFactory)
Initializes a new instance of the HtmlViewOptions class for rendering into HTML with external resources.
For the code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
pageStreamFactory | PageStreamFactory | The factory that implements methods for creating and releasing the output page stream. |
resourceStreamFactory | ResourceStreamFactory | The factory that implements methods for creating resource URLs and instantiating/releasing the output HTML resource stream. |
Returns: HtmlViewOptions - a new instance of the HtmlViewOptions class for rendering into HTML with external resources.
forExternalResources()
public static HtmlViewOptions forExternalResources()
Initializes new instance of HtmlViewOptions class.
- - with “p_{0}.html” as file path format for the output HTML files;
- - with “p_{0}_{1}” as file path format for the output HTML-resource files;
- - with “p_{0}_{1}” as URL format for HTML-resources;
The output files will be placed into current working directory of the application. For the code example, see the documentation.
Returns: HtmlViewOptions
forExternalResources(String filePathFormat, String resourceFilePathFormat, String resourceUrlFormat)
public static HtmlViewOptions forExternalResources(String filePathFormat, String resourceFilePathFormat, String resourceUrlFormat)
Initializes a new instance of the HtmlViewOptions class.
For the code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
filePathFormat | java.lang.String | The file path format, e.g., ‘page_{0}.html’. |
resourceFilePathFormat | java.lang.String | The resource file path format, e.g., ‘page_{0}/resource_{1}’. |
resourceUrlFormat | java.lang.String | The resource URL format, e.g., ‘page_{0}/resource_{1}’. |
Returns: HtmlViewOptions
isRenderResponsive()
public final boolean isRenderResponsive()
Determines whether responsive rendering is enabled. Responsive web pages render well on devices with different screen sizes.
Responsive design aims to make web pages render well on a variety of devices. To render with a responsive layout, set this property to true. For code example, see the documentation.
Returns: boolean - true if responsive rendering is enabled, false otherwise.
setRenderResponsive(boolean value)
public final void setRenderResponsive(boolean value)
Sets whether responsive rendering is enabled. Responsive web pages render well on devices with different screen sizes.
Responsive design aims to make web pages render well on a variety of devices. To render with a responsive layout, set this property to true. For code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean | true to enable responsive rendering, false to disable it. |
isMinify()
public final boolean isMinify()
Checks if HTML content and HTML resources minification is enabled.
Compression of the output content (HTML, CSS, and SVG) is one of the ways to optimize the HTML file. To do this, set this property to true. For code example, see the documentation.
Returns: boolean - true if minification is enabled, false otherwise.
setMinify(boolean value)
public final void setMinify(boolean value)
Sets whether HTML content and HTML resources minification is enabled.
Compression of the output content (HTML, CSS, and SVG) is one of the ways to optimize the HTML file. To do this, set this property to true. For code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean | true to enable minification, false to disable. |
setRenderToSinglePage(boolean renderSinglePage)
public void setRenderToSinglePage(boolean renderSinglePage)
Enables rendering an entire document to one HTML file.
See the following topics for more information:
- Render archives as HTML, PDF, and image files
- Render text documents as HTML, PDF, and image files
- Render Excel and Apple Numbers spreadsheets as HTML, PDF, and image files
- Render web documents as PDF, PNG, and JPEG files
Example:
try (final Viewer viewer = new Viewer("invoice.docx")) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewOptions.setRenderToSinglePage(true);
viewer.view(viewOptions);
}
Parameters:
Parameter | Type | Description |
---|---|---|
renderSinglePage | boolean |
isRenderToSinglePage()
public boolean isRenderToSinglePage()
Enables rendering an entire document to one HTML file.
See the following topics for more information:
- Render archives as HTML, PDF, and image files
- Render text documents as HTML, PDF, and image files
- Render Excel and Apple Numbers spreadsheets as HTML, PDF, and image files
- Render web documents as PDF, PNG, and JPEG files
Example:
try (final Viewer viewer = new Viewer("invoice.docx")) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewOptions.setRenderToSinglePage(true);
viewer.view(viewOptions);
}
Returns: boolean
isExcludeFonts()
public final boolean isExcludeFonts()
Determines whether to exclude fonts from the HTML document.
By default, GroupDocs.Viewer embeds the fonts used in the document into HTML. To prevent it, set this property to true. For details and code example, see the documentation.
Returns: boolean - true if fonts should be excluded, false otherwise.
setExcludeFonts(boolean value)
public final void setExcludeFonts(boolean value)
Sets whether to exclude fonts from the HTML document.
By default, GroupDocs.Viewer embeds the fonts used in the document into HTML. To prevent it, set this property to true. For details and code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean | true to exclude fonts, false otherwise. |
getFontsToExclude()
public final List<String> getFontsToExclude()
Retrieves the list of font names to exclude from the HTML document.
This option is supported for presentations only. Including fonts in the HTML document improves the stability of the output view but increases the rendering result’s size. Use this option to find a compromise between stability and output size. Include font names that are popular and installed on most systems.
Note: Please note that this property is active only when the ExcludeFonts (#isExcludeFonts().isExcludeFonts()/#setExcludeFonts(boolean).setExcludeFonts(boolean)) option is disabled. For details and code example, see the documentation.
Returns: java.util.List<java.lang.String> - the list of font names to exclude from the HTML document.
setFontsToExclude(List value)
public final void setFontsToExclude(List<String> value)
Sets the list of font names to exclude from the HTML document.
This option is supported for presentations only. Including fonts in the HTML document improves the stability of the output view but increases the rendering result’s size. Use this option to find a compromise between stability and output size. Include font names that are popular and installed on most systems.
Note: Please note that this property is active only when the ExcludeFonts (#isExcludeFonts().isExcludeFonts()/#setExcludeFonts(boolean).setExcludeFonts(boolean)) option is disabled. For details and code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.util.List<java.lang.String> | The list of font names to exclude from the HTML document. |
isForPrinting()
public final boolean isForPrinting()
Checks if the output HTML should be optimized for printing.
Enable this option to convert the output HTML pages to the vector SVG format. For details and code example, see the documentation.
Returns: boolean - true if the output HTML should be optimized for printing, false otherwise.
setForPrinting(boolean value)
public final void setForPrinting(boolean value)
Sets whether the output HTML should be optimized for printing.
Enable this option to convert the output HTML pages to the vector SVG format. For details and code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean | true to optimize the output HTML for printing, false otherwise. |
getDocumentSavingCallback()
public IDocumentSavingCallback getDocumentSavingCallback()
Retrieves the callback used to estimate the saving progress of a Words or Email document.
Returns: com.groupdocs.viewer.domain.documents.converting.tohtml.utils.IDocumentSavingCallback - the callback used to estimate the document saving progress.
setDocumentSavingCallback(IDocumentSavingCallback documentSavingCallback)
public void setDocumentSavingCallback(IDocumentSavingCallback documentSavingCallback)
Sets the callback used to estimate the saving progress of a Words or Email document.
Parameters:
Parameter | Type | Description |
---|---|---|
documentSavingCallback | com.groupdocs.viewer.domain.documents.converting.tohtml.utils.IDocumentSavingCallback | The callback used to estimate the document saving progress. |