HtmlSaveOptions Class |
Namespace: Aspose.Words.Saving
The HtmlSaveOptions type exposes the following members.
| Name | Description | |
|---|---|---|
| HtmlSaveOptions |
Initializes a new instance of this class that can be used to save a document
in the Html format.
| |
| HtmlSaveOptions(SaveFormat) |
| Name | Description | |
|---|---|---|
| AllowNegativeIndent |
Specifies whether negative left and right indents of paragraphs are normalized
when saving to HTML, MHTML or EPUB. Default value is false.
| |
| CssClassNamePrefix |
Specifies a prefix which is added to all CSS class names.
Default value is an empty string and generated CSS class names have no common prefix.
| |
| CssSavingCallback |
Allows to control how CSS styles are saved when a document is saved to HTML, MHTML or EPUB.
| |
| CssStyleSheetFileName |
Specifies the path and the name of the Cascading Style Sheet (CSS) file written when a document
is exported to HTML.
Default is an empty string.
| |
| CssStyleSheetType | ||
| DefaultTemplate |
Gets or sets path to default template (including filename).
Default value for this property is empty string (Empty).
(Inherited from SaveOptions.) | |
| DmlEffectsRenderingMode |
Gets or sets a value determining how DrawingML effects are rendered.
(Inherited from SaveOptions.) | |
| DmlRenderingMode |
Gets or sets a value determining how DrawingML shapes are rendered.
(Inherited from SaveOptions.) | |
| DocumentPartSavingCallback |
Allows to control how document parts are saved when a document is saved to HTML or EPUB.
| |
| DocumentSplitCriteria |
Specifies how the document should be split when saving to Html
or Epub format.
Default is None for HTML and
HeadingParagraph for EPUB.
| |
| DocumentSplitHeadingLevel |
Specifies the maximum level of headings at which to split the document.
Default value is 2.
| |
| Encoding |
Specifies the encoding to use when exporting to HTML, MHTML or EPUB.
Default value is new UTF8Encoding(false) (UTF-8 without BOM).
| |
| EpubNavigationMapLevel |
Specifies the maximum level of headings populated to the navigation map when exporting to IDPF EPUB format.
Default value is 3.
| |
| ExportCidUrlsForMhtmlResources |
Specifies whether to use CID (Content-ID) URLs to reference resources (images, fonts, CSS) included in MHTML
documents. Default value is false.
| |
| ExportDocumentProperties |
Specifies whether to export built-in and custom document properties to HTML, MHTML or EPUB.
Default value is false.
| |
| ExportDropDownFormFieldAsText |
Controls how drop-down form fields are saved to HTML or MHTML.
Default value is false.
| |
| ExportFontResources |
Specifies whether font resources should be exported to HTML, MHTML or EPUB.
Default is false.
| |
| ExportFontsAsBase64 |
Specifies whether fonts resources should be embedded to HTML in Base64 encoding.
Default is false.
| |
| ExportHeadersFootersMode |
Specifies how headers and footers are output to HTML, MHTML or EPUB.
Default value is PerSection for HTML/MHTML
and None for EPUB.
| |
| ExportImagesAsBase64 |
Specifies whether images are saved in Base64 format to HTML, MHTML or EPUB.
Default is false.
| |
| ExportLanguageInformation |
Specifies whether language information is exported to HTML, MHTML or EPUB.
Default is false.
| |
| ExportListLabels |
Controls how list labels are output to HTML, MHTML or EPUB.
Default value is Auto.
| |
| ExportOriginalUrlForLinkedImages |
Specifies whether original URL should be used as the URL of the linked images.
Default value is false.
| |
| ExportPageMargins |
Specifies whether page margins is exported to HTML, MHTML or EPUB.
Default is false.
| |
| ExportPageSetup |
Specifies whether page setup is exported to HTML, MHTML or EPUB.
Default is false.
| |
| ExportRelativeFontSize |
Specifies whether font sizes should be output in relative units when saving to HTML, MHTML or EPUB.
Default is false.
| |
| ExportRoundtripInformation |
Specifies whether to write the roundtrip information when saving to HTML, MHTML or EPUB.
Default value is true for HTML and false for MHTML and EPUB.
| |
| ExportTextBoxAsSvg |
Controls how textboxes represented by Shape are saved to HTML, MHTML or EPUB.
Default value is false.
| |
| ExportTextInputFormFieldAsText |
Controls how text input form fields are saved to HTML or MHTML.
Default value is false.
| |
| ExportTocPageNumbers |
Specifies whether to write page numbers to table of contents when saving HTML, MHTML and EPUB.
Default value is false.
| |
| ExportXhtmlTransitional |
Specifies whether to write the DOCTYPE declaration when saving to HTML or MHTML.
When true, writes a DOCTYPE declaration in the document prior to the root element.
Default value is false.
When saving to EPUB or HTML5 (Html5) the DOCTYPE
declaration is always written.
| |
| FontResourcesSubsettingSizeThreshold |
Controls which font resources need subsetting when saving to HTML, MHTML or EPUB.
Default is 0.
| |
| FontSavingCallback |
Allows to control how fonts are saved when a document is saved to HTML, MHTML or EPUB.
| |
| FontsFolder |
Specifies the physical folder where fonts are saved when exporting a document to HTML.
Default is an empty string.
| |
| FontsFolderAlias |
Specifies the name of the folder used to construct font URIs written into an HTML document.
Default is an empty string.
| |
| HtmlVersion |
Specifies version of HTML standard that should be used when saving the document to HTML or MHTML.
Default value is Xhtml.
| |
| ImageResolution |
Specifies the output resolution for images when exporting to HTML, MHTML or EPUB.
Default is 96 dpi.
| |
| ImageSavingCallback |
Allows to control how images are saved when a document is saved to HTML, MHTML or EPUB.
| |
| ImagesFolder |
Specifies the physical folder where images are saved when exporting a document to HTML format.
Default is an empty string.
| |
| ImagesFolderAlias |
Specifies the name of the folder used to construct image URIs written into an HTML document.
Default is an empty string.
| |
| MemoryOptimization |
Gets or sets value determining if memory optimization should be performed before saving the document.
Default value for this property is false.
(Inherited from SaveOptions.) | |
| MetafileFormat |
Specifies in what format metafiles are saved when exporting to HTML, MHTML, or EPUB.
Default value is Png, meaning that metafiles are rendered to raster PNG images.
| |
| OfficeMathOutputMode |
Controls how OfficeMath objects are exported to HTML, MHTML or EPUB.
Default value is HtmlOfficeMathOutputMode.Image.
| |
| PrettyFormat |
When true, pretty formats output where applicable.
Default value is false.
(Inherited from SaveOptions.) | |
| ResolveFontNames |
Specifies whether font family names used in the document are resolved and substituted according to
FontSettings when being written into HTML-based formats.
| |
| ResourceFolder |
Specifies a physical folder where all resources like images, fonts, and external CSS are saved when a document
is exported to HTML. Default is an empty string.
| |
| ResourceFolderAlias |
Specifies the name of the folder used to construct URIs of all resources written into an HTML document.
Default is an empty string.
| |
| SaveFormat |
Specifies the format in which the document will be saved if this save options object is used.
Can be Html, Mhtml
or Epub.
(Overrides SaveOptionsSaveFormat.) | |
| ScaleImageToShapeSize |
Specifies whether images are scaled by Aspose.Words to the bounding shape size when exporting to HTML, MHTML
or EPUB.
Default value is true.
| |
| TableWidthOutputMode |
Controls how table, row and cell widths are exported to HTML, MHTML or EPUB.
Default value is All.
| |
| TempFolder |
Specifies the folder for temporary files used when saving to a DOC or DOCX file.
By default this property is null and no temporary files are used.
(Inherited from SaveOptions.) | |
| UpdateFields |
Gets or sets a value determining if fields of certain types should be updated before saving the document to a fixed page format.
Default value for this property is true.
(Inherited from SaveOptions.) | |
| UpdateLastPrintedProperty |
Gets or sets a value determining whether the LastPrinted property is updated before saving.
(Inherited from SaveOptions.) | |
| UpdateLastSavedTimeProperty |
Gets or sets a value determining whether the LastSavedTime property is updated before saving.
(Inherited from SaveOptions.) | |
| UpdateSdtContent |
Gets or sets value determining whether content of StructuredDocumentTag is updated before saving.
(Inherited from SaveOptions.) | |
| UseAntiAliasing |
Gets or sets a value determining whether or not to use anti-aliasing for rendering.
(Inherited from SaveOptions.) | |
| UseHighQualityRendering |
Gets or sets a value determining whether or not to use high quality (i.e. slow) rendering algorithms.
(Inherited from SaveOptions.) |
| Name | Description | |
|---|---|---|
| Equals | (Inherited from Object.) | |
| GetHashCode | (Inherited from Object.) | |
| GetType | (Inherited from Object.) | |
| ToString | (Inherited from Object.) |
Document doc = new Document(MyDir + "Rendering.docx"); // This is the directory we want the exported images to be saved to string imagesDir = Path.Combine(ArtifactsDir, "SaveHtmlWithOptions"); // The folder specified needs to exist and should be empty if (Directory.Exists(imagesDir)) Directory.Delete(imagesDir, true); Directory.CreateDirectory(imagesDir); // Set an option to export form fields as plain text, not as HTML input elements HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.Html); options.ExportTextInputFormFieldAsText = true; options.ImagesFolder = imagesDir; doc.Save(ArtifactsDir + "Document.SaveHtmlWithOptions.html", options);
// Open an existing document from disk Document doc = new Document(MyDir + "Rendering.docx"); // Create a new instance of HtmlSaveOptions. This object allows us to set options that control // how the output document is saved HtmlSaveOptions saveOptions = new HtmlSaveOptions(); // Specify the desired encoding. saveOptions.Encoding = Encoding.UTF8; // Specify at what elements to split the internal HTML at. This creates a new HTML within the EPUB // which allows you to limit the size of each HTML part. This is useful for readers which cannot read // HTML files greater than a certain size e.g 300kb saveOptions.DocumentSplitCriteria = DocumentSplitCriteria.HeadingParagraph; // Specify that we want to export document properties saveOptions.ExportDocumentProperties = true; // Specify that we want to save in EPUB format saveOptions.SaveFormat = SaveFormat.Epub; // Export the document as an EPUB file doc.Save(ArtifactsDir + "Document.Doc2EpubSaveOptions.epub", saveOptions);
public void DocumentParts() { // Open a document to be converted to html Document doc = new Document(MyDir + "Rendering.docx"); string outFileName = "SavingCallback.DocumentParts.Rendering.html"; // We can use an appropriate SaveOptions subclass to customize the conversion process HtmlSaveOptions options = new HtmlSaveOptions(); // We can use it to split a document into smaller parts, in this instance split by section breaks // Each part will be saved into a separate file, creating many files during the conversion process instead of just one options.DocumentSplitCriteria = DocumentSplitCriteria.SectionBreak; // We can set a callback to name each document part file ourselves options.DocumentPartSavingCallback = new SavedDocumentPartRename(outFileName, options.DocumentSplitCriteria); // If we convert a document that contains images into html, we will end up with one html file which links to several images // Each image will be in the form of a file in the local file system // There is also a callback that can customize the name and file system location of each image options.ImageSavingCallback = new SavedImageRename(outFileName); // The DocumentPartSaving() and ImageSaving() methods of our callbacks will be run at this time doc.Save(ArtifactsDir + outFileName, options); } /// <summary> /// Renames saved document parts that are produced when an HTML document is saved while being split according to a criteria. /// </summary> private class SavedDocumentPartRename : IDocumentPartSavingCallback { public SavedDocumentPartRename(string outFileName, DocumentSplitCriteria documentSplitCriteria) { mOutFileName = outFileName; mDocumentSplitCriteria = documentSplitCriteria; } void IDocumentPartSavingCallback.DocumentPartSaving(DocumentPartSavingArgs args) { Assert.True(args.Document.OriginalFileName.EndsWith("Rendering.docx")); string partType = ""; switch (mDocumentSplitCriteria) { case DocumentSplitCriteria.PageBreak: partType = "Page"; break; case DocumentSplitCriteria.ColumnBreak: partType = "Column"; break; case DocumentSplitCriteria.SectionBreak: partType = "Section"; break; case DocumentSplitCriteria.HeadingParagraph: partType = "Paragraph from heading"; break; } string partFileName = $"{mOutFileName} part {++mCount}, of type {partType}{Path.GetExtension(args.DocumentPartFileName)}"; // We can designate the filename and location of each output file either by filename args.DocumentPartFileName = partFileName; // Or we can make a new stream and choose the location of the file at construction args.DocumentPartStream = new FileStream(ArtifactsDir + partFileName, FileMode.Create); Assert.True(args.DocumentPartStream.CanWrite); Assert.False(args.KeepDocumentPartStreamOpen); } private int mCount; private readonly string mOutFileName; private readonly DocumentSplitCriteria mDocumentSplitCriteria; } /// <summary> /// Renames saved images that are produced when an HTML document is saved. /// </summary> public class SavedImageRename : IImageSavingCallback { public SavedImageRename(string outFileName) { mOutFileName = outFileName; } void IImageSavingCallback.ImageSaving(ImageSavingArgs args) { // Same filename and stream functions as above in IDocumentPartSavingCallback apply here string imageFileName = $"{mOutFileName} shape {++mCount}, of type {args.CurrentShape.ShapeType}{Path.GetExtension(args.ImageFileName)}"; args.ImageFileName = imageFileName; args.ImageStream = new FileStream(ArtifactsDir + imageFileName, FileMode.Create); Assert.True(args.ImageStream.CanWrite); Assert.True(args.IsImageAvailable); Assert.False(args.KeepImageStreamOpen); } private int mCount; private readonly string mOutFileName; }