Class HtmlFixedSaveOptions

Class HtmlFixedSaveOptions

Namespace: Aspose.Words.Saving
Assembly: Aspose.Words.dll (25.12.0)

Can be used to specify additional options when saving a document into the Aspose.Words.SaveFormat.HtmlFixed format.

To learn more, visit the Specify Save Options documentation article.

public class HtmlFixedSaveOptions : FixedPageSaveOptions

Inheritance

object SaveOptions FixedPageSaveOptions HtmlFixedSaveOptions

Inherited Members

FixedPageSaveOptions.Equals(object) , FixedPageSaveOptions.AssertValidIdPrefix(string) , FixedPageSaveOptions.IsValidIdPrefix(string) , FixedPageSaveOptions.PageSet , FixedPageSaveOptions.PageSavingCallback , FixedPageSaveOptions.NumeralFormat , FixedPageSaveOptions.MetafileRenderingOptions , FixedPageSaveOptions.JpegQuality , FixedPageSaveOptions.ColorMode , FixedPageSaveOptions.OptimizeOutput , SaveOptions.CreateSaveOptions(SaveFormat) , SaveOptions.CreateSaveOptions(string) , SaveOptions.SaveFormat , SaveOptions.ExportGeneratorName , SaveOptions.TempFolder , SaveOptions.PrettyFormat , SaveOptions.UseAntiAliasing , SaveOptions.UseHighQualityRendering , SaveOptions.DmlRenderingMode , SaveOptions.DmlEffectsRenderingMode , SaveOptions.ImlRenderingMode , SaveOptions.DefaultTemplate , SaveOptions.UpdateFields , SaveOptions.UpdateLastSavedTimeProperty , SaveOptions.UpdateLastPrintedProperty , SaveOptions.UpdateCreatedTimeProperty , SaveOptions.MemoryOptimization , SaveOptions.UpdateAmbiguousTextFont , SaveOptions.Dml3DEffectsRenderingMode , SaveOptions.ProgressCallback , SaveOptions.AllowEmbeddingPostScriptFonts , SaveOptions.CustomTimeZoneInfo , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

Shows how to use a callback to print the URIs of external resources created while converting a document to HTML.

public void HtmlFixedResourceFolder()
                                                                                                                           {
                                                                                                                               Document doc = new Document(MyDir + "Rendering.docx");

                                                                                                                               ResourceUriPrinter callback = new ResourceUriPrinter();

                                                                                                                               HtmlFixedSaveOptions options = new HtmlFixedSaveOptions
                                                                                                                               {
                                                                                                                                   SaveFormat = SaveFormat.HtmlFixed,
                                                                                                                                   ExportEmbeddedImages = false,
                                                                                                                                   ResourcesFolder = ArtifactsDir + "HtmlFixedResourceFolder",
                                                                                                                                   ResourcesFolderAlias = ArtifactsDir + "HtmlFixedResourceFolderAlias",
                                                                                                                                   ShowPageBorder = false,
                                                                                                                                   ResourceSavingCallback = callback
                                                                                                                               };

                                                                                                                               // A folder specified by ResourcesFolderAlias will contain the resources instead of ResourcesFolder.
                                                                                                                               // We must ensure the folder exists before the streams can put their resources into it.
                                                                                                                               Directory.CreateDirectory(options.ResourcesFolderAlias);

                                                                                                                               doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);

                                                                                                                               Console.WriteLine(callback.GetText());

                                                                                                                               string[] resourceFiles = Directory.GetFiles(ArtifactsDir + "HtmlFixedResourceFolderAlias");

                                                                                                                               Assert.That(Directory.Exists(ArtifactsDir + "HtmlFixedResourceFolder"), Is.False);
                                                                                                                               Assert.That(resourceFiles.Count(f => f.EndsWith(".jpeg") || f.EndsWith(".png") || f.EndsWith(".css")), Is.EqualTo(6));
                                                                                                                           }

                                                                                                                           /// <summary>
                                                                                                                           /// Counts and prints URIs of resources contained by as they are converted to fixed HTML.
                                                                                                                           /// </summary>
                                                                                                                           private class ResourceUriPrinter : IResourceSavingCallback
                                                                                                                           {
                                                                                                                               void IResourceSavingCallback.ResourceSaving(ResourceSavingArgs args)
                                                                                                                               {
                                                                                                                                   // If we set a folder alias in the SaveOptions object, we will be able to print it from here.
                                                                                                                                   mText.AppendLine($"Resource #{++mSavedResourceCount} \"{args.ResourceFileName}\"");

                                                                                                                                   string extension = Path.GetExtension(args.ResourceFileName);
                                                                                                                                   switch (extension)
                                                                                                                                   {
                                                                                                                                       case ".ttf":
                                                                                                                                       case ".woff":
                                                                                                                                       {
                                                                                                                                           // By default, 'ResourceFileUri' uses system folder for fonts.
                                                                                                                                           // To avoid problems in other platforms you must explicitly specify the path for the fonts.
                                                                                                                                           args.ResourceFileUri = ArtifactsDir + Path.DirectorySeparatorChar + args.ResourceFileName;
                                                                                                                                           break;
                                                                                                                                       }
                                                                                                                                   }

                                                                                                                                   mText.AppendLine("\t" + args.ResourceFileUri);

                                                                                                                                   // If we have specified a folder in the "ResourcesFolderAlias" property,
                                                                                                                                   // we will also need to redirect each stream to put its resource in that folder.
                                                                                                                                   args.ResourceStream = new FileStream(args.ResourceFileUri, FileMode.Create);
                                                                                                                                   args.KeepResourceStreamOpen = false;
                                                                                                                               }

                                                                                                                               public string GetText()
                                                                                                                               {
                                                                                                                                   return mText.ToString();
                                                                                                                               }

                                                                                                                               private int mSavedResourceCount;
                                                                                                                               private readonly StringBuilder mText = new StringBuilder();
                                                                                                                           }

Constructors

HtmlFixedSaveOptions()

public HtmlFixedSaveOptions()

Properties

CssClassNamesPrefix

Specifies prefix which is added to all class names in style.css file. Default value is “aw”.

public string CssClassNamesPrefix { get; set; }

Property Value

string

Examples

Shows how to place CSS into a separate file and add a prefix to all of its CSS class names.

Document doc = new Document(MyDir + "Bookmarks.docx");

                                                                                                      HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions
                                                                                                      {
                                                                                                          CssClassNamesPrefix = "myprefix",
                                                                                                          SaveFontFaceCssSeparately = true
                                                                                                      };

                                                                                                      doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.AddCssClassNamesPrefix.html", htmlFixedSaveOptions);

                                                                                                      string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.AddCssClassNamesPrefix.html");

                                                                                                      Assert.That(Regex.Match(outDocContents,
                                                                                                          "<div class=\"myprefixdiv myprefixpage\" style=\"width:595[.]3pt; height:841[.]9pt;\">" +
                                                                                                          "<div class=\"myprefixdiv\" style=\"left:85[.]05pt; top:36pt; clip:rect[(]0pt,510[.]25pt,74[.]95pt,-85.05pt[)];\">" +
                                                                                                          "<span class=\"myprefixspan myprefixtext001\" style=\"font-size:11pt; left:294[.]73pt; top:0[.]36pt; line-height:12[.]29pt;\">").Success, Is.True);

                                                                                                      outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.AddCssClassNamesPrefix/styles.css");

                                                                                                      Assert.That(Regex.Match(outDocContents,
                                                                                                          ".myprefixdiv { position:absolute; } " +
                                                                                                          ".myprefixspan { position:absolute; white-space:pre; color:#000000; font-size:12pt; }").Success, Is.True);

Encoding

Specifies the encoding to use when exporting to HTML. Default value is new UTF8Encoding(true) (UTF-8 with BOM).

public Encoding Encoding { get; set; }

Property Value

Encoding

Examples

Shows how to set which encoding to use while exporting a document to HTML.

Document doc = new Document();
                                                                                     DocumentBuilder builder = new DocumentBuilder(doc);

                                                                                     builder.Writeln("Hello World!");

                                                                                     // The default encoding is UTF-8. If we want to represent our document using a different encoding,
                                                                                     // we can use a SaveOptions object to set a specific encoding.
                                                                                     HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions
                                                                                     {
                                                                                         Encoding = Encoding.ASCII
                                                                                     };

                                                                                     Assert.That(htmlFixedSaveOptions.Encoding.EncodingName, Is.EqualTo("US-ASCII"));

                                                                                     doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.UseEncoding.html", htmlFixedSaveOptions);

ExportEmbeddedCss

Specifies whether the CSS (Cascading Style Sheet) should be embedded into Html document.

public bool ExportEmbeddedCss { get; set; }

Property Value

bool

Examples

Shows how to determine where to store CSS stylesheets when exporting a document to Html.

Document doc = new Document(MyDir + "Rendering.docx");

                                                                                                   // When we export a document to html, Aspose.Words will also create a CSS stylesheet to format the document with.
                                                                                                   // Setting the "ExportEmbeddedCss" flag to "true" save the CSS stylesheet to a .css file,
                                                                                                   // and link to the file from the html document using a <link> element.
                                                                                                   // Setting the flag to "false" will embed the CSS stylesheet within the Html document,
                                                                                                   // which will create only one file instead of two.
                                                                                                   HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions
                                                                                                   {
                                                                                                       ExportEmbeddedCss = exportEmbeddedCss
                                                                                                   };

                                                                                                   doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedCss.html", htmlFixedSaveOptions);

                                                                                                   string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedCss.html");

                                                                                                   if (exportEmbeddedCss)
                                                                                                   {
                                                                                                       Assert.That(Regex.Match(outDocContents, "<style type=\"text/css\">").Success, Is.True);
                                                                                                       Assert.That(File.Exists(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedCss/styles.css"), Is.False);
                                                                                                   }
                                                                                                   else
                                                                                                   {
                                                                                                       Assert.That(Regex.Match(outDocContents,
                                                                                                           "<link rel=\"stylesheet\" type=\"text/css\" href=\"HtmlFixedSaveOptions[.]ExportEmbeddedCss/styles[.]css\" media=\"all\" />").Success, Is.True);
                                                                                                       Assert.That(File.Exists(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedCss/styles.css"), Is.True);
                                                                                                   }

ExportEmbeddedFonts

Specifies whether fonts should be embedded into Html document in Base64 format. Note setting this flag can significantly increase size of output Html file.

public bool ExportEmbeddedFonts { get; set; }

Property Value

bool

Examples

Shows how to determine where to store embedded fonts when exporting a document to Html.

Document doc = new Document(MyDir + "Embedded font.docx");

                                                                                                  // When we export a document with embedded fonts to .html,
                                                                                                  // Aspose.Words can place the fonts in two possible locations.
                                                                                                  // Setting the "ExportEmbeddedFonts" flag to "true" will store the raw data for embedded fonts within the CSS stylesheet,
                                                                                                  // in the "url" property of the "@font-face" rule. This may create a huge CSS stylesheet file
                                                                                                  // and reduce the number of external files that this HTML conversion will create.
                                                                                                  // Setting this flag to "false" will create a file for each font.
                                                                                                  // The CSS stylesheet will link to each font file using the "url" property of the "@font-face" rule.
                                                                                                  HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions
                                                                                                  {
                                                                                                      ExportEmbeddedFonts = exportEmbeddedFonts
                                                                                                  };

                                                                                                  doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedFonts.html", htmlFixedSaveOptions);

                                                                                                  string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedFonts/styles.css");

                                                                                                  if (exportEmbeddedFonts)
                                                                                                  {
                                                                                                      Assert.That(Regex.Match(outDocContents,
                                                                                                          "@font-face { font-family:'Arial'; font-style:normal; font-weight:normal; src:local[(]'☺'[)], url[(].+[)] format[(]'woff'[)]; }").Success, Is.True);
                                                                                                      Assert.That(Directory.GetFiles(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedFonts").Count(f => f.EndsWith(".woff")), Is.EqualTo(0));
                                                                                                  }
                                                                                                  else
                                                                                                  {
                                                                                                      Assert.That(Regex.Match(outDocContents,
                                                                                                          "@font-face { font-family:'Arial'; font-style:normal; font-weight:normal; src:local[(]'☺'[)], url[(]'font001[.]woff'[)] format[(]'woff'[)]; }").Success, Is.True);
                                                                                                      Assert.That(Directory.GetFiles(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedFonts").Count(f => f.EndsWith(".woff")), Is.EqualTo(2));
                                                                                                  }

ExportEmbeddedImages

Specifies whether images should be embedded into Html document in Base64 format. Note setting this flag can significantly increase size of output Html file.

public bool ExportEmbeddedImages { get; set; }

Property Value

bool

Examples

Shows how to determine where to store images when exporting a document to Html.

Document doc = new Document(MyDir + "Images.docx");

                                                                                          // When we export a document with embedded images to .html,
                                                                                          // Aspose.Words can place the images in two possible locations.
                                                                                          // Setting the "ExportEmbeddedImages" flag to "true" will store the raw data
                                                                                          // for all images within the output HTML document, in the "src" attribute of <image> tags.
                                                                                          // Setting this flag to "false" will create an image file in the local file system for every image,
                                                                                          // and store all these files in a separate folder.
                                                                                          HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions
                                                                                          {
                                                                                              ExportEmbeddedImages = exportImages
                                                                                          };

                                                                                          doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedImages.html", htmlFixedSaveOptions);

                                                                                          string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedImages.html");

                                                                                          if (exportImages)
                                                                                          {
                                                                                              Assert.That(File.Exists(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedImages/image001.jpeg"), Is.False);
                                                                                              Assert.That(Regex.Match(outDocContents,
                                                                                                  "<img class=\"awimg\" style=\"left:0pt; top:0pt; width:493.1pt; height:300.55pt;\" src=\".+\" />").Success, Is.True);
                                                                                          }
                                                                                          else
                                                                                          {
                                                                                              Assert.That(File.Exists(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedImages/image001.jpeg"), Is.True);
                                                                                              Assert.That(Regex.Match(outDocContents,
                                                                                                  "<img class=\"awimg\" style=\"left:0pt; top:0pt; width:493.1pt; height:300.55pt;\" " +
                                                                                                  "src=\"HtmlFixedSaveOptions[.]ExportEmbeddedImages/image001[.]jpeg\" />").Success, Is.True);
                                                                                          }

ExportEmbeddedSvg

Specifies whether SVG resources should be embedded into Html document. Default value is true.

public bool ExportEmbeddedSvg { get; set; }

Property Value

bool

Examples

Shows how to determine where to store SVG objects when exporting a document to Html.

Document doc = new Document(MyDir + "Images.docx");

                                                                                               // When we export a document with SVG objects to .html,
                                                                                               // Aspose.Words can place these objects in two possible locations.
                                                                                               // Setting the "ExportEmbeddedSvg" flag to "true" will embed all SVG object raw data
                                                                                               // within the output HTML, inside <image> tags.
                                                                                               // Setting this flag to "false" will create a file in the local file system for each SVG object.
                                                                                               // The HTML will link to each file using the "data" attribute of an <object> tag.
                                                                                               HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions
                                                                                               {
                                                                                                   ExportEmbeddedSvg = exportSvgs
                                                                                               };

                                                                                               doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedSvgs.html", htmlFixedSaveOptions);

                                                                                               string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedSvgs.html");

                                                                                               if (exportSvgs)
                                                                                               {
                                                                                                   Assert.That(File.Exists(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedSvgs/svg001.svg"), Is.False);
                                                                                                   Assert.That(Regex.Match(outDocContents,
                                                                                                       "<image id=\"image004\" xlink:href=.+/>").Success, Is.True);
                                                                                               }
                                                                                               else
                                                                                               {
                                                                                                   Assert.That(File.Exists(ArtifactsDir + "HtmlFixedSaveOptions.ExportEmbeddedSvgs/svg001.svg"), Is.True);
                                                                                                   Assert.That(Regex.Match(outDocContents,
                                                                                                       "<object type=\"image/svg[+]xml\" data=\"HtmlFixedSaveOptions.ExportEmbeddedSvgs/svg001[.]svg\"></object>").Success, Is.True);
                                                                                               }

ExportFormFields

Gets or sets indication of whether form fields are exported as interactive items (as ‘input’ tag) rather than converted to text or graphics.

public bool ExportFormFields { get; set; }

Property Value

bool

Examples

Shows how to export form fields to Html.

Document doc = new Document();
                                                   DocumentBuilder builder = new DocumentBuilder(doc);

                                                   builder.InsertCheckBox("CheckBox", false, 15);

                                                   // When we export a document with form fields to .html,
                                                   // there are two ways in which Aspose.Words can export form fields.
                                                   // Setting the "ExportFormFields" flag to "true" will export them as interactive objects.
                                                   // Setting this flag to "false" will display form fields as plain text.
                                                   // This will freeze them at their current value, and prevent the reader of our HTML document
                                                   // from being able to interact with them.
                                                   HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions
                                                   {
                                                       ExportFormFields = exportFormFields
                                                   };

                                                   doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.ExportFormFields.html", htmlFixedSaveOptions);

                                                   string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.ExportFormFields.html");

                                                   if (exportFormFields)
                                                   {
                                                       Assert.That(Regex.Match(outDocContents,
                                                           "<a name=\"CheckBox\" style=\"left:0pt; top:0pt;\"></a>" +
                                                           "<input style=\"position:absolute; left:0pt; top:0pt;\" type=\"checkbox\" name=\"CheckBox\" />").Success, Is.True);
                                                   }
                                                   else
                                                   {
                                                       Assert.That(Regex.Match(outDocContents,
                                                           "<a name=\"CheckBox\" style=\"left:0pt; top:0pt;\"></a>" +
                                                           "<div class=\"awdiv\" style=\"left:0.8pt; top:0.8pt; width:14.25pt; height:14.25pt; border:solid 0.75pt #000000;\"").Success, Is.True);
                                                   }

FontFormat

Gets or sets Aspose.Words.Saving.ExportFontFormat used for font exporting. Default value is Aspose.Words.Saving.ExportFontFormat.Woff.

public ExportFontFormat FontFormat { get; set; }

Property Value

ExportFontFormat

Examples

Shows how use fonts only from the target machine when saving a document to HTML.

Document doc = new Document(MyDir + "Bullet points with alternative font.docx");

                                                                                           HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions
                                                                                           {
                                                                                               ExportEmbeddedCss = true,
                                                                                               UseTargetMachineFonts = useTargetMachineFonts,
                                                                                               FontFormat = ExportFontFormat.Ttf,
                                                                                               ExportEmbeddedFonts = false,
                                                                                           };

                                                                                           doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.UsingMachineFonts.html", saveOptions);

                                                                                           string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.UsingMachineFonts.html");

                                                                                           if (useTargetMachineFonts)
                                                                                               Assert.That(Regex.Match(outDocContents, "@font-face").Success, Is.False);
                                                                                           else
                                                                                               Assert.That(Regex.Match(outDocContents,
                                                                                                   "@font-face { font-family:'Arial'; font-style:normal; font-weight:normal; src:local[(]'☺'[)], " +
                                                                                                   "url[(]'HtmlFixedSaveOptions.UsingMachineFonts/font001.ttf'[)] format[(]'truetype'[)]; }").Success, Is.True);

IdPrefix

Specifies a prefix that is prepended to all generated element IDs in the output document. Default value is null and no prefix is prepended.

public string IdPrefix { get; set; }

Property Value

string

Examples

Shows how to add a prefix that is prepended to all generated element IDs.

Document doc = new Document(MyDir + "Id prefix.docx");

                                                                                    HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions();
                                                                                    saveOptions.IdPrefix = "pfx1_";

                                                                                    doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.IdPrefix.html", saveOptions);

Remarks

If the prefix is specified, it can contain only letters, digits, underscores, and hyphens, and must start with a letter.

Exceptions

ArgumentException

The value does not meet the requirements specified above.

OptimizeOutput

Flag indicates whether it is required to optimize output. If this flag is set redundant nested canvases and empty canvases are removed, also neighbor glyphs with the same formating are concatenated. Note: The accuracy of the content display may be affected if this property is set to true.

Default is true.

public override bool OptimizeOutput { get; set; }

Property Value

bool

Examples

Shows how to simplify a document when saving it to HTML by removing various redundant objects.

Document doc = new Document(MyDir + "Rendering.docx");

                                                                                                         HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions { OptimizeOutput = optimizeOutput };

                                                                                                         doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.OptimizeGraphicsOutput.html", saveOptions);

                                                                                                         // The size of the optimized version of the document is almost a third of the size of the unoptimized document.
                                                                                                         Assert.That(new FileInfo(ArtifactsDir + "HtmlFixedSaveOptions.OptimizeGraphicsOutput.html").Length, Is.EqualTo(optimizeOutput ? 60385 : 191000).Within(200));

PageHorizontalAlignment

Specifies the horizontal alignment of pages in an HTML document. Default value is Aspose.Words.Saving.HtmlFixedPageHorizontalAlignment.Center.

public HtmlFixedPageHorizontalAlignment PageHorizontalAlignment { get; set; }

Property Value

HtmlFixedPageHorizontalAlignment

Examples

Shows how to set the horizontal alignment of pages when saving a document to HTML.

Document doc = new Document(MyDir + "Rendering.docx");

                                                                                             HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions
                                                                                             {
                                                                                                 PageHorizontalAlignment = pageHorizontalAlignment
                                                                                             };

                                                                                             doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.HorizontalAlignment.html", htmlFixedSaveOptions);

                                                                                             string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.HorizontalAlignment/styles.css");

                                                                                             switch (pageHorizontalAlignment)
                                                                                             {
                                                                                                 case HtmlFixedPageHorizontalAlignment.Center:
                                                                                                     Assert.That(Regex.Match(outDocContents,
                                                                                                         "[.]awpage { position:relative; border:solid 1pt black; margin:10pt auto 10pt auto; overflow:hidden; }").Success, Is.True);
                                                                                                     break;
                                                                                                 case HtmlFixedPageHorizontalAlignment.Left:
                                                                                                     Assert.That(Regex.Match(outDocContents,
                                                                                                         "[.]awpage { position:relative; border:solid 1pt black; margin:10pt auto 10pt 10pt; overflow:hidden; }").Success, Is.True);
                                                                                                     break;
                                                                                                 case HtmlFixedPageHorizontalAlignment.Right:
                                                                                                     Assert.That(Regex.Match(outDocContents,
                                                                                                         "[.]awpage { position:relative; border:solid 1pt black; margin:10pt 10pt 10pt auto; overflow:hidden; }").Success, Is.True);
                                                                                                     break;
                                                                                             }

PageMargins

Specifies the margins around pages in an HTML document. The margins value is measured in points and should be equal to or greater than 0. Default value is 10 points.

public double PageMargins { get; set; }

Property Value

double

Examples

Shows how to adjust page margins when saving a document to HTML.

Document doc = new Document(MyDir + "Document.docx");

                                                                           HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions
                                                                           {
                                                                               PageMargins = 15
                                                                           };

                                                                           doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.PageMargins.html", saveOptions);

                                                                           string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.PageMargins/styles.css");

                                                                           Assert.That(Regex.Match(outDocContents,
                                                                               "[.]awpage { position:relative; border:solid 1pt black; margin:15pt auto 15pt auto; overflow:hidden; }").Success, Is.True);

Remarks

Depends on the value of Aspose.Words.Saving.HtmlFixedSaveOptions.PageHorizontalAlignment property:

  • Defines top, bottom and left page margins if the value is Aspose.Words.Saving.HtmlFixedPageHorizontalAlignment.Left.
  • Defines top, bottom and right page margins if the value is Aspose.Words.Saving.HtmlFixedPageHorizontalAlignment.Right.
  • Defines top and bottom page margins if the value is Aspose.Words.Saving.HtmlFixedPageHorizontalAlignment.Center.

RemoveJavaScriptFromLinks

Specifies whether JavaScript will be removed from links. Default is false.

public bool RemoveJavaScriptFromLinks { get; set; }

Property Value

bool

Examples

Shows how to remove JavaScript from the links.

Document doc = new Document(MyDir + "JavaScript in HREF.docx");

                                                         HtmlSaveOptions saveOptions = new HtmlSaveOptions();
                                                         saveOptions.RemoveJavaScriptFromLinks = true;

                                                         doc.Save(ArtifactsDir + "HtmlSaveOptions.RemoveJavaScriptFromLinks.html", saveOptions);

Shows how to remove JavaScript from the links for html fixed documents.

Document doc = new Document(MyDir + "JavaScript in HREF.docx");

                                                                                  HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions();
                                                                                  saveOptions.RemoveJavaScriptFromLinks = true;

                                                                                  doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.RemoveJavaScriptFromLinks.html", saveOptions);

Remarks

If this option is enabled, all links containing JavaScript (e.g., links with “javascript:” in the href attribute) will be replaced with “javascript:void(0)”. This can help prevent potential security risks, such as XSS attacks.

ResourceSavingCallback

Allows to control how resources (images, fonts and css) are saved when a document is exported to fixed page Html format.

public IResourceSavingCallback ResourceSavingCallback { get; set; }

Property Value

IResourceSavingCallback

Examples

Shows how to use a callback to print the URIs of external resources created while converting a document to HTML.

public void HtmlFixedResourceFolder()
                                                                                                                           {
                                                                                                                               Document doc = new Document(MyDir + "Rendering.docx");

                                                                                                                               ResourceUriPrinter callback = new ResourceUriPrinter();

                                                                                                                               HtmlFixedSaveOptions options = new HtmlFixedSaveOptions
                                                                                                                               {
                                                                                                                                   SaveFormat = SaveFormat.HtmlFixed,
                                                                                                                                   ExportEmbeddedImages = false,
                                                                                                                                   ResourcesFolder = ArtifactsDir + "HtmlFixedResourceFolder",
                                                                                                                                   ResourcesFolderAlias = ArtifactsDir + "HtmlFixedResourceFolderAlias",
                                                                                                                                   ShowPageBorder = false,
                                                                                                                                   ResourceSavingCallback = callback
                                                                                                                               };

                                                                                                                               // A folder specified by ResourcesFolderAlias will contain the resources instead of ResourcesFolder.
                                                                                                                               // We must ensure the folder exists before the streams can put their resources into it.
                                                                                                                               Directory.CreateDirectory(options.ResourcesFolderAlias);

                                                                                                                               doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);

                                                                                                                               Console.WriteLine(callback.GetText());

                                                                                                                               string[] resourceFiles = Directory.GetFiles(ArtifactsDir + "HtmlFixedResourceFolderAlias");

                                                                                                                               Assert.That(Directory.Exists(ArtifactsDir + "HtmlFixedResourceFolder"), Is.False);
                                                                                                                               Assert.That(resourceFiles.Count(f => f.EndsWith(".jpeg") || f.EndsWith(".png") || f.EndsWith(".css")), Is.EqualTo(6));
                                                                                                                           }

                                                                                                                           /// <summary>
                                                                                                                           /// Counts and prints URIs of resources contained by as they are converted to fixed HTML.
                                                                                                                           /// </summary>
                                                                                                                           private class ResourceUriPrinter : IResourceSavingCallback
                                                                                                                           {
                                                                                                                               void IResourceSavingCallback.ResourceSaving(ResourceSavingArgs args)
                                                                                                                               {
                                                                                                                                   // If we set a folder alias in the SaveOptions object, we will be able to print it from here.
                                                                                                                                   mText.AppendLine($"Resource #{++mSavedResourceCount} \"{args.ResourceFileName}\"");

                                                                                                                                   string extension = Path.GetExtension(args.ResourceFileName);
                                                                                                                                   switch (extension)
                                                                                                                                   {
                                                                                                                                       case ".ttf":
                                                                                                                                       case ".woff":
                                                                                                                                       {
                                                                                                                                           // By default, 'ResourceFileUri' uses system folder for fonts.
                                                                                                                                           // To avoid problems in other platforms you must explicitly specify the path for the fonts.
                                                                                                                                           args.ResourceFileUri = ArtifactsDir + Path.DirectorySeparatorChar + args.ResourceFileName;
                                                                                                                                           break;
                                                                                                                                       }
                                                                                                                                   }

                                                                                                                                   mText.AppendLine("\t" + args.ResourceFileUri);

                                                                                                                                   // If we have specified a folder in the "ResourcesFolderAlias" property,
                                                                                                                                   // we will also need to redirect each stream to put its resource in that folder.
                                                                                                                                   args.ResourceStream = new FileStream(args.ResourceFileUri, FileMode.Create);
                                                                                                                                   args.KeepResourceStreamOpen = false;
                                                                                                                               }

                                                                                                                               public string GetText()
                                                                                                                               {
                                                                                                                                   return mText.ToString();
                                                                                                                               }

                                                                                                                               private int mSavedResourceCount;
                                                                                                                               private readonly StringBuilder mText = new StringBuilder();
                                                                                                                           }

ResourcesFolder

Specifies the physical folder where resources (images, fonts, css) are saved when exporting a document to Html format. Default is null.

public string ResourcesFolder { get; set; }

Property Value

string

Examples

Shows how to use a callback to print the URIs of external resources created while converting a document to HTML.

public void HtmlFixedResourceFolder()
                                                                                                                           {
                                                                                                                               Document doc = new Document(MyDir + "Rendering.docx");

                                                                                                                               ResourceUriPrinter callback = new ResourceUriPrinter();

                                                                                                                               HtmlFixedSaveOptions options = new HtmlFixedSaveOptions
                                                                                                                               {
                                                                                                                                   SaveFormat = SaveFormat.HtmlFixed,
                                                                                                                                   ExportEmbeddedImages = false,
                                                                                                                                   ResourcesFolder = ArtifactsDir + "HtmlFixedResourceFolder",
                                                                                                                                   ResourcesFolderAlias = ArtifactsDir + "HtmlFixedResourceFolderAlias",
                                                                                                                                   ShowPageBorder = false,
                                                                                                                                   ResourceSavingCallback = callback
                                                                                                                               };

                                                                                                                               // A folder specified by ResourcesFolderAlias will contain the resources instead of ResourcesFolder.
                                                                                                                               // We must ensure the folder exists before the streams can put their resources into it.
                                                                                                                               Directory.CreateDirectory(options.ResourcesFolderAlias);

                                                                                                                               doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);

                                                                                                                               Console.WriteLine(callback.GetText());

                                                                                                                               string[] resourceFiles = Directory.GetFiles(ArtifactsDir + "HtmlFixedResourceFolderAlias");

                                                                                                                               Assert.That(Directory.Exists(ArtifactsDir + "HtmlFixedResourceFolder"), Is.False);
                                                                                                                               Assert.That(resourceFiles.Count(f => f.EndsWith(".jpeg") || f.EndsWith(".png") || f.EndsWith(".css")), Is.EqualTo(6));
                                                                                                                           }

                                                                                                                           /// <summary>
                                                                                                                           /// Counts and prints URIs of resources contained by as they are converted to fixed HTML.
                                                                                                                           /// </summary>
                                                                                                                           private class ResourceUriPrinter : IResourceSavingCallback
                                                                                                                           {
                                                                                                                               void IResourceSavingCallback.ResourceSaving(ResourceSavingArgs args)
                                                                                                                               {
                                                                                                                                   // If we set a folder alias in the SaveOptions object, we will be able to print it from here.
                                                                                                                                   mText.AppendLine($"Resource #{++mSavedResourceCount} \"{args.ResourceFileName}\"");

                                                                                                                                   string extension = Path.GetExtension(args.ResourceFileName);
                                                                                                                                   switch (extension)
                                                                                                                                   {
                                                                                                                                       case ".ttf":
                                                                                                                                       case ".woff":
                                                                                                                                       {
                                                                                                                                           // By default, 'ResourceFileUri' uses system folder for fonts.
                                                                                                                                           // To avoid problems in other platforms you must explicitly specify the path for the fonts.
                                                                                                                                           args.ResourceFileUri = ArtifactsDir + Path.DirectorySeparatorChar + args.ResourceFileName;
                                                                                                                                           break;
                                                                                                                                       }
                                                                                                                                   }

                                                                                                                                   mText.AppendLine("\t" + args.ResourceFileUri);

                                                                                                                                   // If we have specified a folder in the "ResourcesFolderAlias" property,
                                                                                                                                   // we will also need to redirect each stream to put its resource in that folder.
                                                                                                                                   args.ResourceStream = new FileStream(args.ResourceFileUri, FileMode.Create);
                                                                                                                                   args.KeepResourceStreamOpen = false;
                                                                                                                               }

                                                                                                                               public string GetText()
                                                                                                                               {
                                                                                                                                   return mText.ToString();
                                                                                                                               }

                                                                                                                               private int mSavedResourceCount;
                                                                                                                               private readonly StringBuilder mText = new StringBuilder();
                                                                                                                           }

Remarks

Has effect only if Aspose.Words.Saving.HtmlFixedSaveOptions.ExportEmbeddedImages property is false.

When you save a Aspose.Words.Document in Html format, Aspose.Words needs to save all images embedded in the document as standalone files. Aspose.Words.Saving.HtmlFixedSaveOptions.ResourcesFolder allows you to specify where the images will be saved and Aspose.Words.Saving.HtmlFixedSaveOptions.ResourcesFolderAlias allows to specify how the image URIs will be constructed.

If you save a document into a file and provide a file name, Aspose.Words, by default, saves the images in the same folder where the document file is saved. Use Aspose.Words.Saving.HtmlFixedSaveOptions.ResourcesFolder to override this behavior.

If you save a document into a stream, Aspose.Words does not have a folder where to save the images, but still needs to save the images somewhere. In this case, you need to specify an accessible folder by using the Aspose.Words.Saving.HtmlFixedSaveOptions.ResourcesFolder property

Aspose.Words.Saving.HtmlFixedSaveOptions.ResourcesFolderAlias

ResourcesFolderAlias

Specifies the name of the folder used to construct image URIs written into an Html document. Default is null.

public string ResourcesFolderAlias { get; set; }

Property Value

string

Examples

Shows how to use a callback to print the URIs of external resources created while converting a document to HTML.

public void HtmlFixedResourceFolder()
                                                                                                                           {
                                                                                                                               Document doc = new Document(MyDir + "Rendering.docx");

                                                                                                                               ResourceUriPrinter callback = new ResourceUriPrinter();

                                                                                                                               HtmlFixedSaveOptions options = new HtmlFixedSaveOptions
                                                                                                                               {
                                                                                                                                   SaveFormat = SaveFormat.HtmlFixed,
                                                                                                                                   ExportEmbeddedImages = false,
                                                                                                                                   ResourcesFolder = ArtifactsDir + "HtmlFixedResourceFolder",
                                                                                                                                   ResourcesFolderAlias = ArtifactsDir + "HtmlFixedResourceFolderAlias",
                                                                                                                                   ShowPageBorder = false,
                                                                                                                                   ResourceSavingCallback = callback
                                                                                                                               };

                                                                                                                               // A folder specified by ResourcesFolderAlias will contain the resources instead of ResourcesFolder.
                                                                                                                               // We must ensure the folder exists before the streams can put their resources into it.
                                                                                                                               Directory.CreateDirectory(options.ResourcesFolderAlias);

                                                                                                                               doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);

                                                                                                                               Console.WriteLine(callback.GetText());

                                                                                                                               string[] resourceFiles = Directory.GetFiles(ArtifactsDir + "HtmlFixedResourceFolderAlias");

                                                                                                                               Assert.That(Directory.Exists(ArtifactsDir + "HtmlFixedResourceFolder"), Is.False);
                                                                                                                               Assert.That(resourceFiles.Count(f => f.EndsWith(".jpeg") || f.EndsWith(".png") || f.EndsWith(".css")), Is.EqualTo(6));
                                                                                                                           }

                                                                                                                           /// <summary>
                                                                                                                           /// Counts and prints URIs of resources contained by as they are converted to fixed HTML.
                                                                                                                           /// </summary>
                                                                                                                           private class ResourceUriPrinter : IResourceSavingCallback
                                                                                                                           {
                                                                                                                               void IResourceSavingCallback.ResourceSaving(ResourceSavingArgs args)
                                                                                                                               {
                                                                                                                                   // If we set a folder alias in the SaveOptions object, we will be able to print it from here.
                                                                                                                                   mText.AppendLine($"Resource #{++mSavedResourceCount} \"{args.ResourceFileName}\"");

                                                                                                                                   string extension = Path.GetExtension(args.ResourceFileName);
                                                                                                                                   switch (extension)
                                                                                                                                   {
                                                                                                                                       case ".ttf":
                                                                                                                                       case ".woff":
                                                                                                                                       {
                                                                                                                                           // By default, 'ResourceFileUri' uses system folder for fonts.
                                                                                                                                           // To avoid problems in other platforms you must explicitly specify the path for the fonts.
                                                                                                                                           args.ResourceFileUri = ArtifactsDir + Path.DirectorySeparatorChar + args.ResourceFileName;
                                                                                                                                           break;
                                                                                                                                       }
                                                                                                                                   }

                                                                                                                                   mText.AppendLine("\t" + args.ResourceFileUri);

                                                                                                                                   // If we have specified a folder in the "ResourcesFolderAlias" property,
                                                                                                                                   // we will also need to redirect each stream to put its resource in that folder.
                                                                                                                                   args.ResourceStream = new FileStream(args.ResourceFileUri, FileMode.Create);
                                                                                                                                   args.KeepResourceStreamOpen = false;
                                                                                                                               }

                                                                                                                               public string GetText()
                                                                                                                               {
                                                                                                                                   return mText.ToString();
                                                                                                                               }

                                                                                                                               private int mSavedResourceCount;
                                                                                                                               private readonly StringBuilder mText = new StringBuilder();
                                                                                                                           }

Remarks

When you save a Aspose.Words.Document in Html format, Aspose.Words needs to save all images embedded in the document as standalone files. Aspose.Words.Saving.HtmlFixedSaveOptions.ResourcesFolder allows you to specify where the images will be saved and Aspose.Words.Saving.HtmlFixedSaveOptions.ResourcesFolderAlias allows to specify how the image URIs will be constructed.

Aspose.Words.Saving.HtmlFixedSaveOptions.ResourcesFolder

SaveFontFaceCssSeparately

Flag indicates whether “@font-face” CSS rules should be placed into a separate file “fontFaces.css” when a document is being saved with external stylesheet (that is, when Aspose.Words.Saving.HtmlFixedSaveOptions.ExportEmbeddedCss is false). Default value is false, all CSS rules are written into single file “styles.css”.

public bool SaveFontFaceCssSeparately { get; set; }

Property Value

bool

Examples

Shows how to place CSS into a separate file and add a prefix to all of its CSS class names.

Document doc = new Document(MyDir + "Bookmarks.docx");

                                                                                                      HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions
                                                                                                      {
                                                                                                          CssClassNamesPrefix = "myprefix",
                                                                                                          SaveFontFaceCssSeparately = true
                                                                                                      };

                                                                                                      doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.AddCssClassNamesPrefix.html", htmlFixedSaveOptions);

                                                                                                      string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.AddCssClassNamesPrefix.html");

                                                                                                      Assert.That(Regex.Match(outDocContents,
                                                                                                          "<div class=\"myprefixdiv myprefixpage\" style=\"width:595[.]3pt; height:841[.]9pt;\">" +
                                                                                                          "<div class=\"myprefixdiv\" style=\"left:85[.]05pt; top:36pt; clip:rect[(]0pt,510[.]25pt,74[.]95pt,-85.05pt[)];\">" +
                                                                                                          "<span class=\"myprefixspan myprefixtext001\" style=\"font-size:11pt; left:294[.]73pt; top:0[.]36pt; line-height:12[.]29pt;\">").Success, Is.True);

                                                                                                      outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.AddCssClassNamesPrefix/styles.css");

                                                                                                      Assert.That(Regex.Match(outDocContents,
                                                                                                          ".myprefixdiv { position:absolute; } " +
                                                                                                          ".myprefixspan { position:absolute; white-space:pre; color:#000000; font-size:12pt; }").Success, Is.True);

Remarks

Setting this property to true restores the old behavior (separate files) for compatibility with legacy code.

SaveFormat

Specifies the format in which the document will be saved if this save options object is used. Can only be Aspose.Words.SaveFormat.HtmlFixed.

public override SaveFormat SaveFormat { get; set; }

Property Value

SaveFormat

Examples

Shows how to use a callback to print the URIs of external resources created while converting a document to HTML.

public void HtmlFixedResourceFolder()
                                                                                                                           {
                                                                                                                               Document doc = new Document(MyDir + "Rendering.docx");

                                                                                                                               ResourceUriPrinter callback = new ResourceUriPrinter();

                                                                                                                               HtmlFixedSaveOptions options = new HtmlFixedSaveOptions
                                                                                                                               {
                                                                                                                                   SaveFormat = SaveFormat.HtmlFixed,
                                                                                                                                   ExportEmbeddedImages = false,
                                                                                                                                   ResourcesFolder = ArtifactsDir + "HtmlFixedResourceFolder",
                                                                                                                                   ResourcesFolderAlias = ArtifactsDir + "HtmlFixedResourceFolderAlias",
                                                                                                                                   ShowPageBorder = false,
                                                                                                                                   ResourceSavingCallback = callback
                                                                                                                               };

                                                                                                                               // A folder specified by ResourcesFolderAlias will contain the resources instead of ResourcesFolder.
                                                                                                                               // We must ensure the folder exists before the streams can put their resources into it.
                                                                                                                               Directory.CreateDirectory(options.ResourcesFolderAlias);

                                                                                                                               doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);

                                                                                                                               Console.WriteLine(callback.GetText());

                                                                                                                               string[] resourceFiles = Directory.GetFiles(ArtifactsDir + "HtmlFixedResourceFolderAlias");

                                                                                                                               Assert.That(Directory.Exists(ArtifactsDir + "HtmlFixedResourceFolder"), Is.False);
                                                                                                                               Assert.That(resourceFiles.Count(f => f.EndsWith(".jpeg") || f.EndsWith(".png") || f.EndsWith(".css")), Is.EqualTo(6));
                                                                                                                           }

                                                                                                                           /// <summary>
                                                                                                                           /// Counts and prints URIs of resources contained by as they are converted to fixed HTML.
                                                                                                                           /// </summary>
                                                                                                                           private class ResourceUriPrinter : IResourceSavingCallback
                                                                                                                           {
                                                                                                                               void IResourceSavingCallback.ResourceSaving(ResourceSavingArgs args)
                                                                                                                               {
                                                                                                                                   // If we set a folder alias in the SaveOptions object, we will be able to print it from here.
                                                                                                                                   mText.AppendLine($"Resource #{++mSavedResourceCount} \"{args.ResourceFileName}\"");

                                                                                                                                   string extension = Path.GetExtension(args.ResourceFileName);
                                                                                                                                   switch (extension)
                                                                                                                                   {
                                                                                                                                       case ".ttf":
                                                                                                                                       case ".woff":
                                                                                                                                       {
                                                                                                                                           // By default, 'ResourceFileUri' uses system folder for fonts.
                                                                                                                                           // To avoid problems in other platforms you must explicitly specify the path for the fonts.
                                                                                                                                           args.ResourceFileUri = ArtifactsDir + Path.DirectorySeparatorChar + args.ResourceFileName;
                                                                                                                                           break;
                                                                                                                                       }
                                                                                                                                   }

                                                                                                                                   mText.AppendLine("\t" + args.ResourceFileUri);

                                                                                                                                   // If we have specified a folder in the "ResourcesFolderAlias" property,
                                                                                                                                   // we will also need to redirect each stream to put its resource in that folder.
                                                                                                                                   args.ResourceStream = new FileStream(args.ResourceFileUri, FileMode.Create);
                                                                                                                                   args.KeepResourceStreamOpen = false;
                                                                                                                               }

                                                                                                                               public string GetText()
                                                                                                                               {
                                                                                                                                   return mText.ToString();
                                                                                                                               }

                                                                                                                               private int mSavedResourceCount;
                                                                                                                               private readonly StringBuilder mText = new StringBuilder();
                                                                                                                           }

ShowPageBorder

Specifies whether border around pages should be shown. Default is true.

public bool ShowPageBorder { get; set; }

Property Value

bool

Examples

Shows how to use a callback to print the URIs of external resources created while converting a document to HTML.

public void HtmlFixedResourceFolder()
                                                                                                                           {
                                                                                                                               Document doc = new Document(MyDir + "Rendering.docx");

                                                                                                                               ResourceUriPrinter callback = new ResourceUriPrinter();

                                                                                                                               HtmlFixedSaveOptions options = new HtmlFixedSaveOptions
                                                                                                                               {
                                                                                                                                   SaveFormat = SaveFormat.HtmlFixed,
                                                                                                                                   ExportEmbeddedImages = false,
                                                                                                                                   ResourcesFolder = ArtifactsDir + "HtmlFixedResourceFolder",
                                                                                                                                   ResourcesFolderAlias = ArtifactsDir + "HtmlFixedResourceFolderAlias",
                                                                                                                                   ShowPageBorder = false,
                                                                                                                                   ResourceSavingCallback = callback
                                                                                                                               };

                                                                                                                               // A folder specified by ResourcesFolderAlias will contain the resources instead of ResourcesFolder.
                                                                                                                               // We must ensure the folder exists before the streams can put their resources into it.
                                                                                                                               Directory.CreateDirectory(options.ResourcesFolderAlias);

                                                                                                                               doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);

                                                                                                                               Console.WriteLine(callback.GetText());

                                                                                                                               string[] resourceFiles = Directory.GetFiles(ArtifactsDir + "HtmlFixedResourceFolderAlias");

                                                                                                                               Assert.That(Directory.Exists(ArtifactsDir + "HtmlFixedResourceFolder"), Is.False);
                                                                                                                               Assert.That(resourceFiles.Count(f => f.EndsWith(".jpeg") || f.EndsWith(".png") || f.EndsWith(".css")), Is.EqualTo(6));
                                                                                                                           }

                                                                                                                           /// <summary>
                                                                                                                           /// Counts and prints URIs of resources contained by as they are converted to fixed HTML.
                                                                                                                           /// </summary>
                                                                                                                           private class ResourceUriPrinter : IResourceSavingCallback
                                                                                                                           {
                                                                                                                               void IResourceSavingCallback.ResourceSaving(ResourceSavingArgs args)
                                                                                                                               {
                                                                                                                                   // If we set a folder alias in the SaveOptions object, we will be able to print it from here.
                                                                                                                                   mText.AppendLine($"Resource #{++mSavedResourceCount} \"{args.ResourceFileName}\"");

                                                                                                                                   string extension = Path.GetExtension(args.ResourceFileName);
                                                                                                                                   switch (extension)
                                                                                                                                   {
                                                                                                                                       case ".ttf":
                                                                                                                                       case ".woff":
                                                                                                                                       {
                                                                                                                                           // By default, 'ResourceFileUri' uses system folder for fonts.
                                                                                                                                           // To avoid problems in other platforms you must explicitly specify the path for the fonts.
                                                                                                                                           args.ResourceFileUri = ArtifactsDir + Path.DirectorySeparatorChar + args.ResourceFileName;
                                                                                                                                           break;
                                                                                                                                       }
                                                                                                                                   }

                                                                                                                                   mText.AppendLine("\t" + args.ResourceFileUri);

                                                                                                                                   // If we have specified a folder in the "ResourcesFolderAlias" property,
                                                                                                                                   // we will also need to redirect each stream to put its resource in that folder.
                                                                                                                                   args.ResourceStream = new FileStream(args.ResourceFileUri, FileMode.Create);
                                                                                                                                   args.KeepResourceStreamOpen = false;
                                                                                                                               }

                                                                                                                               public string GetText()
                                                                                                                               {
                                                                                                                                   return mText.ToString();
                                                                                                                               }

                                                                                                                               private int mSavedResourceCount;
                                                                                                                               private readonly StringBuilder mText = new StringBuilder();
                                                                                                                           }

UseTargetMachineFonts

Flag indicates whether fonts from target machine must be used to display the document. If this flag is set to true, Aspose.Words.Saving.HtmlFixedSaveOptions.FontFormat and Aspose.Words.Saving.HtmlFixedSaveOptions.ExportEmbeddedFonts properties do not have effect, also Aspose.Words.Saving.HtmlFixedSaveOptions.ResourceSavingCallback is not fired for fonts. Default is false.

public bool UseTargetMachineFonts { get; set; }

Property Value

bool

Examples

Shows how use fonts only from the target machine when saving a document to HTML.

Document doc = new Document(MyDir + "Bullet points with alternative font.docx");

                                                                                           HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions
                                                                                           {
                                                                                               ExportEmbeddedCss = true,
                                                                                               UseTargetMachineFonts = useTargetMachineFonts,
                                                                                               FontFormat = ExportFontFormat.Ttf,
                                                                                               ExportEmbeddedFonts = false,
                                                                                           };

                                                                                           doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.UsingMachineFonts.html", saveOptions);

                                                                                           string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlFixedSaveOptions.UsingMachineFonts.html");

                                                                                           if (useTargetMachineFonts)
                                                                                               Assert.That(Regex.Match(outDocContents, "@font-face").Success, Is.False);
                                                                                           else
                                                                                               Assert.That(Regex.Match(outDocContents,
                                                                                                   "@font-face { font-family:'Arial'; font-style:normal; font-weight:normal; src:local[(]'☺'[)], " +
                                                                                                   "url[(]'HtmlFixedSaveOptions.UsingMachineFonts/font001.ttf'[)] format[(]'truetype'[)]; }").Success, Is.True);
 English