Aspose::Words::Saving::HtmlFixedSaveOptions Class Reference

Detailed Description

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

Examples

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

void HtmlFixedResourceFolder()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto callback = MakeObject<ExHtmlFixedSaveOptions::ResourceUriPrinter>();
auto options = MakeObject<HtmlFixedSaveOptions>();
options->set_SaveFormat(SaveFormat::HtmlFixed);
options->set_ExportEmbeddedImages(false);
options->set_ResourcesFolder(ArtifactsDir + u"HtmlFixedResourceFolder");
options->set_ResourcesFolderAlias(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
options->set_ShowPageBorder(false);
options->set_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.
System::IO::Directory::CreateDirectory_(options->get_ResourcesFolderAlias());
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);
std::cout << callback->GetText() << std::endl;
ArrayPtr<String> resourceFiles = System::IO::Directory::GetFiles(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
ASSERT_FALSE(System::IO::Directory::Exists(ArtifactsDir + u"HtmlFixedResourceFolder"));
std::function<bool(String f)> isImageOrCss = [](String f)
{
return f.EndsWith(u".jpeg") || f.EndsWith(u".png") || f.EndsWith(u".css");
};
ASSERT_EQ(6, resourceFiles->LINQ_Count(isImageOrCss));
}
class ResourceUriPrinter : public IResourceSavingCallback
{
public:
void ResourceSaving(SharedPtr<ResourceSavingArgs> args) override
{
// If we set a folder alias in the SaveOptions object, we will be able to print it from here.
mText->AppendLine(String::Format(u"Resource #{0} \"{1}\"", ++mSavedResourceCount, args->get_ResourceFileName()));
String extension = System::IO::Path::GetExtension(args->get_ResourceFileName());
if (extension == u".ttf" || extension == u".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->set_ResourceFileUri(ArtifactsDir + System::IO::Path::DirectorySeparatorChar + args->get_ResourceFileName());
}
mText->AppendLine(String(u"\t") + args->get_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->set_ResourceStream(MakeObject<System::IO::FileStream>(args->get_ResourceFileUri(), System::IO::FileMode::Create));
args->set_KeepResourceStreamOpen(false);
}
String GetText()
{
return mText->ToString();
}
ResourceUriPrinter() : mSavedResourceCount(0), mText(MakeObject<System::Text::StringBuilder>())
{
}
private:
int mSavedResourceCount;
SharedPtr<System::Text::StringBuilder> mText;
};
static const char_t ASPOSECPP_SHARED_API DirectorySeparatorChar
static ASPOSECPP_SHARED_API void CreateDirectory_(const String &path)
static ASPOSECPP_SHARED_API String GetExtension(const String &path)
static ASPOSECPP_SHARED_API bool Exists(const String &path)
static ASPOSECPP_SHARED_API ArrayPtr< String > GetFiles(const String &path, const String &searchPattern=u"*", SearchOption searchOption=SearchOption::TopDirectoryOnly)
std::enable_if<!IsSmartPtr< T >::value, SmartPtr< T > >::type MakeObject(Args &&... args)
@ HtmlFixed
Saves the document in the HTML format using absolutely positioned elements.

#include <Aspose.Words.Cpp/Model/Saving/HtmlFixedSaveOptions.h>

+ Inheritance diagram for Aspose::Words::Saving::HtmlFixedSaveOptions:

Public Member Functions

 HtmlFixedSaveOptions ()
 
String get_CssClassNamesPrefix () const
 Specifies prefix which is added to all class names in style.css file. Default value is "aw". More...
 
SharedPtr< Encodingget_Encoding () const
 Specifies the encoding to use when exporting to HTML. Default value is new UTF8Encoding(true) (UTF-8 with BOM). More...
 
bool get_ExportEmbeddedCss () const
 Specifies whether the CSS (Cascading Style Sheet) should be embedded into Html document. More...
 
bool get_ExportEmbeddedFonts () const
 Specifies whether fonts should be embedded into Html document in Base64 format. Note setting this flag can significantly increase size of output Html file. More...
 
bool get_ExportEmbeddedImages () const
 Specifies whether images should be embedded into Html document in Base64 format. Note setting this flag can significantly increase size of output Html file. More...
 
bool get_ExportEmbeddedSvg () const
 Specifies whether SVG resources should be embedded into Html document. Default value is true. More...
 
bool get_ExportFormFields () const
 Gets or sets indication of whether form fields are exported as interactive items (as 'input' tag) rather than converted to text or graphics. More...
 
ExportFontFormat get_FontFormat () const
 Gets or sets ExportFontFormat used for font exporting. Default value is Woff. More...
 
bool get_OptimizeOutput () override
 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. More...
 
HtmlFixedPageHorizontalAlignment get_PageHorizontalAlignment () const
 Specifies the horizontal alignment of pages in an HTML document. Default value is HtmlFixedHorizontalPageAlignment.Center. More...
 
double get_PageMargins () const
 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. More...
 
SharedPtr< IResourceSavingCallbackget_ResourceSavingCallback () const
 Allows to control how resources (images, fonts and css) are saved when a document is exported to fixed page Html format. More...
 
String get_ResourcesFolder () const
 Specifies the physical folder where resources (images, fonts, css) are saved when exporting a document to Html format. Default is null. More...
 
String get_ResourcesFolderAlias () const
 Specifies the name of the folder used to construct image URIs written into an Html document. Default is null. More...
 
bool get_SaveFontFaceCssSeparately () const
 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 ExportEmbeddedCss is false). Default value is false, all CSS rules are written into single file "styles.css". More...
 
SaveFormat get_SaveFormat () override
 Specifies the format in which the document will be saved if this save options object is used. Can only be HtmlFixed. More...
 
bool get_ShowPageBorder () const
 Specifies whether border around pages should be shown. Default is true. More...
 
bool get_UseTargetMachineFonts () const
 Flag indicates whether fonts from target machine must be used to display the document. If this flag is set to true, FontFormat and ExportEmbeddedFonts properties do not have effect, also ResourceSavingCallback is not fired for fonts. Default is false. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_CssClassNamesPrefix (String value)
 Setter for get_CssClassNamesPrefix. More...
 
void set_Encoding (SharedPtr< Encoding > value)
 Setter for get_Encoding. More...
 
void set_ExportEmbeddedCss (bool value)
 Setter for get_ExportEmbeddedCss. More...
 
void set_ExportEmbeddedFonts (bool value)
 Setter for get_ExportEmbeddedFonts. More...
 
void set_ExportEmbeddedImages (bool value)
 Setter for get_ExportEmbeddedImages. More...
 
void set_ExportEmbeddedSvg (bool value)
 Setter for get_ExportEmbeddedSvg. More...
 
void set_ExportFormFields (bool value)
 Setter for get_ExportFormFields. More...
 
void set_FontFormat (ExportFontFormat value)
 Setter for get_FontFormat. More...
 
void set_OptimizeOutput (bool value) override
 Setter for get_OptimizeOutput. More...
 
void set_PageHorizontalAlignment (HtmlFixedPageHorizontalAlignment value)
 Setter for get_PageHorizontalAlignment. More...
 
void set_PageMargins (double value)
 Setter for get_PageMargins. More...
 
void set_ResourceSavingCallback (SharedPtr< IResourceSavingCallback > value)
 Setter for get_ResourceSavingCallback. More...
 
void set_ResourcesFolder (String value)
 Setter for get_ResourcesFolder. More...
 
void set_ResourcesFolderAlias (String value)
 Setter for get_ResourcesFolderAlias. More...
 
void set_SaveFontFaceCssSeparately (bool value)
 Setter for get_SaveFontFaceCssSeparately. More...
 
void set_SaveFormat (SaveFormat value) override
 Setter for get_SaveFormat. More...
 
void set_ShowPageBorder (bool value)
 Setter for get_ShowPageBorder. More...
 
void set_UseTargetMachineFonts (bool value)
 Setter for get_UseTargetMachineFonts. More...
 
- Public Member Functions inherited from FixedPageSaveOptions
bool Equals (SharedPtr< Object > obj) override
 Determines whether the specified object is equal in value to the current object. More...
 
ColorMode get_ColorMode () const
 Gets or sets a value determining how colors are rendered. More...
 
int32_t get_JpegQuality () const
 Gets or sets a value determining the quality of the JPEG images inside Html document. More...
 
SharedPtr< MetafileRenderingOptionsget_MetafileRenderingOptions () const
 Allows to specify metafile rendering options. More...
 
NumeralFormat get_NumeralFormat () const
 Gets or sets NumeralFormat used for rendering of numerals. European numerals are used by default. More...
 
SharedPtr< IPageSavingCallbackget_PageSavingCallback () const
 Allows to control how separate pages are saved when a document is exported to fixed page format. More...
 
SharedPtr< PageSetget_PageSet () const
 Gets or sets the pages to render. Default is all the pages in the document. More...
 
void set_ColorMode (ColorMode value)
 Setter for get_ColorMode. More...
 
void set_JpegQuality (int32_t value)
 Setter for get_JpegQuality. More...
 
void set_MetafileRenderingOptions (SharedPtr< MetafileRenderingOptions > value)
 Setter for get_MetafileRenderingOptions. More...
 
void set_NumeralFormat (NumeralFormat value)
 Setter for get_NumeralFormat. More...
 
void set_PageSavingCallback (SharedPtr< IPageSavingCallback > value)
 Setter for get_PageSavingCallback. More...
 
void set_PageSet (SharedPtr< PageSet > value)
 Setter for get_PageSet. More...
 
- Public Member Functions inherited from SaveOptions
bool get_AllowEmbeddingPostScriptFonts () const
 Gets or sets a boolean value indicating whether to allow embedding fonts with PostScript outlines when embedding TrueType fonts in a document upon it is saved. The default value is false. More...
 
SharedPtr< TimeZoneInfoget_CustomTimeZoneInfo () const
 
String get_DefaultTemplate () const
 Gets or sets path to default template (including filename). Default value for this property is empty string (Empty). More...
 
Dml3DEffectsRenderingMode get_Dml3DEffectsRenderingMode () const
 Gets a value determining how 3D effects are rendered. More...
 
virtual DmlEffectsRenderingMode get_DmlEffectsRenderingMode ()
 Gets or sets a value determining how DrawingML effects are rendered. More...
 
DmlRenderingMode get_DmlRenderingMode () const
 Gets or sets a value determining how DrawingML shapes are rendered. More...
 
bool get_MemoryOptimization () const
 Gets or sets value determining if memory optimization should be performed before saving the document. Default value for this property is false. More...
 
bool get_PrettyFormat () const
 When true, pretty formats output where applicable. Default value is false. More...
 
String get_TempFolder () const
 Specifies the folder for temporary files used when saving to a DOC or DOCX file. By default this property is null and no temporary files are used. More...
 
bool get_UpdateCreatedTimeProperty () const
 Gets a value determining whether the CreatedTime property is updated before saving. Default value is false;. More...
 
bool get_UpdateFields () const
 Gets or sets a value determining if fields of certain types should be updated before saving the document to a fixed page format. Default value for this property is true. More...
 
bool get_UpdateLastPrintedProperty () const
 Gets or sets a value determining whether the LastPrinted property is updated before saving. More...
 
bool get_UpdateLastSavedTimeProperty () const
 Gets or sets a value determining whether the LastSavedTime property is updated before saving. More...
 
bool get_UpdateSdtContent () const
 Gets or sets value determining whether content of StructuredDocumentTag is updated before saving. More...
 
bool get_UseAntiAliasing () const
 Gets or sets a value determining whether or not to use anti-aliasing for rendering. More...
 
bool get_UseHighQualityRendering () const
 Gets or sets a value determining whether or not to use high quality (i.e. slow) rendering algorithms. More...
 
void set_AllowEmbeddingPostScriptFonts (bool value)
 Setter for get_AllowEmbeddingPostScriptFonts. More...
 
void set_CustomTimeZoneInfo (SharedPtr< TimeZoneInfo > value)
 
void set_DefaultTemplate (String value)
 Setter for get_DefaultTemplate. More...
 
void set_Dml3DEffectsRenderingMode (Dml3DEffectsRenderingMode value)
 Sets a value determining how 3D effects are rendered. More...
 
virtual void set_DmlEffectsRenderingMode (DmlEffectsRenderingMode value)
 Setter for get_DmlEffectsRenderingMode. More...
 
void set_DmlRenderingMode (DmlRenderingMode value)
 Setter for get_DmlRenderingMode. More...
 
void set_MemoryOptimization (bool value)
 Setter for get_MemoryOptimization. More...
 
void set_PrettyFormat (bool value)
 Setter for get_PrettyFormat. More...
 
void set_TempFolder (String value)
 Setter for get_TempFolder. More...
 
void set_UpdateCreatedTimeProperty (bool value)
 Sets a value determining whether the CreatedTime property is updated before saving. Default value is false;. More...
 
void set_UpdateFields (bool value)
 Setter for get_UpdateFields. More...
 
void set_UpdateLastPrintedProperty (bool value)
 Setter for get_UpdateLastPrintedProperty. More...
 
void set_UpdateLastSavedTimeProperty (bool value)
 Setter for get_UpdateLastSavedTimeProperty. More...
 
void set_UpdateSdtContent (bool value)
 Setter for get_UpdateSdtContent. More...
 
void set_UseAntiAliasing (bool value)
 Setter for get_UseAntiAliasing. More...
 
void set_UseHighQualityRendering (bool value)
 Setter for get_UseHighQualityRendering. More...
 
- Public Member Functions inherited from Object
ASPOSECPP_SHARED_API Object ()
 
ASPOSECPP_SHARED_API Object (Object const &x)
 
virtual ASPOSECPP_SHARED_API ~Object ()
 
virtual ASPOSECPP_SHARED_API bool Equals (ptr obj)
 
virtual ASPOSECPP_SHARED_API bool FastCast (const Details::FastRttiBase &helper, void **out_ptr) const
 
Detail::SmartPtrCounter * GetCounter ()
 
virtual ASPOSECPP_SHARED_API int32_t GetHashCode () const
 
ASPOSECPP_SHARED_API void Lock ()
 
virtual ASPOSECPP_SHARED_API ptr MemberwiseClone () const
 
Objectoperator= (Object const &x)
 
bool ReferenceEquals (String const &str, std::nullptr_t)
 
bool ReferenceEquals (String const &str1, String const &str2)
 
int RemovedSharedRefs (int count)
 
virtual ASPOSECPP_SHARED_API void SetTemplateWeakPtr (uint32_t argument)
 
int SharedCount () const
 
ObjectSharedRefAdded ()
 
int SharedRefRemovedSafe ()
 
virtual ASPOSECPP_SHARED_API String ToString () const
 
ASPOSECPP_SHARED_API void Unlock ()
 
Detail::SmartPtrCounter * WeakRefAdded ()
 
void WeakRefRemoved ()
 

Static Public Member Functions

static const TypeInfoType ()
 
- Static Public Member Functions inherited from FixedPageSaveOptions
static const TypeInfoType ()
 
- Static Public Member Functions inherited from SaveOptions
static SharedPtr< SaveOptionsCreateSaveOptions (SaveFormat saveFormat)
 Creates a save options object of a class suitable for the specified save format. More...
 
static SharedPtr< SaveOptionsCreateSaveOptions (String fileName)
 Creates a save options object of a class suitable for the file extension specified in the given file name. More...
 
static const TypeInfoType ()
 
- Static Public Member Functions inherited from Object
bool Equals (double const &objA, double const &objB)
 
bool Equals (float const &objA, float const &objB)
 
static std::enable_if<!IsSmartPtr< T1 >::value &&!IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static bool ReferenceEquals (ptr const &objA, ptr const &objB)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, std::nullptr_t)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, T const &objB)
 
static const TypeInfoType ()
 

Additional Inherited Members

- Public Types inherited from Object
typedef SmartPtr< Objectptr
 

Constructor & Destructor Documentation

◆ HtmlFixedSaveOptions()

Aspose::Words::Saving::HtmlFixedSaveOptions::HtmlFixedSaveOptions ( )

Member Function Documentation

◆ get_CssClassNamesPrefix()

System::String Aspose::Words::Saving::HtmlFixedSaveOptions::get_CssClassNamesPrefix ( ) const

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

Examples

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

auto doc = MakeObject<Document>(MyDir + u"Bookmarks.docx");
auto htmlFixedSaveOptions = MakeObject<HtmlFixedSaveOptions>();
htmlFixedSaveOptions->set_CssClassNamesPrefix(u"myprefix");
htmlFixedSaveOptions->set_SaveFontFaceCssSeparately(true);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.AddCssClassNamesPrefix.html", htmlFixedSaveOptions);
String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.AddCssClassNamesPrefix.html");
ASSERT_TRUE(
outDocContents, String(u"<div class=\"myprefixdiv myprefixpage\" style=\"width:595[.]3pt; height:841[.]9pt;\">") +
u"<div class=\"myprefixdiv\" style=\"left:85[.]05pt; top:36pt; clip:rect[(]0pt,510[.]25pt,74[.]95pt,-85.05pt[)];\">" +
u"<span class=\"myprefixspan myprefixtext001\" style=\"font-size:11pt; left:294[.]73pt; top:0[.]36pt;\">")
->get_Success());
outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.AddCssClassNamesPrefix/styles.css");
String(u".myprefixdiv { position:absolute; } ") +
u".myprefixspan { position:absolute; white-space:pre; color:#000000; font-size:12pt; }")
->get_Success());
static ASPOSECPP_SHARED_API String ReadAllText(const String &path, const EncodingPtr &encoding=Text::Encoding::get_UTF8())

◆ get_Encoding()

System::SharedPtr<System::Text::Encoding> Aspose::Words::Saving::HtmlFixedSaveOptions::get_Encoding ( ) const

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

Examples

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

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"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.
auto htmlFixedSaveOptions = MakeObject<HtmlFixedSaveOptions>();
htmlFixedSaveOptions->set_Encoding(System::Text::Encoding::GetEncoding(u"ASCII"));
ASSERT_EQ(u"US-ASCII", htmlFixedSaveOptions->get_Encoding()->get_EncodingName());
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.UseEncoding.html", htmlFixedSaveOptions);
static ASPOSECPP_SHARED_API EncodingPtr GetEncoding(const String &name)

◆ get_ExportEmbeddedCss()

bool Aspose::Words::Saving::HtmlFixedSaveOptions::get_ExportEmbeddedCss ( ) const

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

Examples

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

auto doc = MakeObject<Document>(MyDir + u"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.
auto htmlFixedSaveOptions = MakeObject<HtmlFixedSaveOptions>();
htmlFixedSaveOptions->set_ExportEmbeddedCss(exportEmbeddedCss);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedCss.html", htmlFixedSaveOptions);
String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedCss.html");
if (exportEmbeddedCss)
{
ASSERT_TRUE(System::Text::RegularExpressions::Regex::Match(outDocContents, u"<style type=\"text/css\">")->get_Success());
ASSERT_FALSE(System::IO::File::Exists(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedCss/styles.css"));
}
else
{
outDocContents,
u"<link rel=\"stylesheet\" type=\"text/css\" href=\"HtmlFixedSaveOptions[.]ExportEmbeddedCss/styles[.]css\" media=\"all\" />")
->get_Success());
ASSERT_TRUE(System::IO::File::Exists(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedCss/styles.css"));
}
static ASPOSECPP_SHARED_API bool Exists(const String &path)

◆ get_ExportEmbeddedFonts()

bool Aspose::Words::Saving::HtmlFixedSaveOptions::get_ExportEmbeddedFonts ( ) const

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

Examples

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

auto doc = MakeObject<Document>(MyDir + u"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.
auto htmlFixedSaveOptions = MakeObject<HtmlFixedSaveOptions>();
htmlFixedSaveOptions->set_ExportEmbeddedFonts(exportEmbeddedFonts);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedFonts.html", htmlFixedSaveOptions);
String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedFonts/styles.css");
if (exportEmbeddedFonts)
{
outDocContents,
u"@font-face { font-family:'Arial'; font-style:normal; font-weight:normal; src:local[(]'☺'[)], url[(].+[)] format[(]'woff'[)]; }")
->get_Success());
ASSERT_EQ(0, System::IO::Directory::GetFiles(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedFonts")
->LINQ_Count([](String f) { return f.EndsWith(u".woff"); }));
}
else
{
ASSERT_TRUE(
System::Text::RegularExpressions::Regex::Match(outDocContents, u"@font-face { font-family:'Arial'; font-style:normal; font-weight:normal; "
u"src:local[(]'☺'[)], url[(]'font001[.]woff'[)] format[(]'woff'[)]; }")
->get_Success());
ASSERT_EQ(2, System::IO::Directory::GetFiles(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedFonts")
->LINQ_Count([](String f) { return f.EndsWith(u".woff"); }));
}

◆ get_ExportEmbeddedImages()

bool Aspose::Words::Saving::HtmlFixedSaveOptions::get_ExportEmbeddedImages ( ) const

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

Examples

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

auto doc = MakeObject<Document>(MyDir + u"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.
auto htmlFixedSaveOptions = MakeObject<HtmlFixedSaveOptions>();
htmlFixedSaveOptions->set_ExportEmbeddedImages(exportImages);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedImages.html", htmlFixedSaveOptions);
String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedImages.html");
if (exportImages)
{
ASSERT_FALSE(System::IO::File::Exists(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedImages/image001.jpeg"));
outDocContents, u"<img class=\"awimg\" style=\"left:0pt; top:0pt; width:493.1pt; height:300.55pt;\" src=\".+\" />")
->get_Success());
}
else
{
ASSERT_TRUE(System::IO::File::Exists(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedImages/image001.jpeg"));
outDocContents, String(u"<img class=\"awimg\" style=\"left:0pt; top:0pt; width:493.1pt; height:300.55pt;\" ") +
u"src=\"HtmlFixedSaveOptions[.]ExportEmbeddedImages/image001[.]jpeg\" />")
->get_Success());
}

◆ get_ExportEmbeddedSvg()

bool Aspose::Words::Saving::HtmlFixedSaveOptions::get_ExportEmbeddedSvg ( ) const

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

Examples

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

auto doc = MakeObject<Document>(MyDir + u"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.
auto htmlFixedSaveOptions = MakeObject<HtmlFixedSaveOptions>();
htmlFixedSaveOptions->set_ExportEmbeddedSvg(exportSvgs);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedSvgs.html", htmlFixedSaveOptions);
String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedSvgs.html");
if (exportSvgs)
{
ASSERT_FALSE(System::IO::File::Exists(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedSvgs/svg001.svg"));
ASSERT_TRUE(System::Text::RegularExpressions::Regex::Match(outDocContents, u"<image id=\"image004\" xlink:href=.+/>")->get_Success());
}
else
{
ASSERT_TRUE(System::IO::File::Exists(ArtifactsDir + u"HtmlFixedSaveOptions.ExportEmbeddedSvgs/svg001.svg"));
outDocContents, u"<object type=\"image/svg[+]xml\" data=\"HtmlFixedSaveOptions.ExportEmbeddedSvgs/svg001[.]svg\"></object>")
->get_Success());
}

◆ get_ExportFormFields()

bool Aspose::Words::Saving::HtmlFixedSaveOptions::get_ExportFormFields ( ) const

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

Examples

Shows how to export form fields to Html.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->InsertCheckBox(u"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.
auto htmlFixedSaveOptions = MakeObject<HtmlFixedSaveOptions>();
htmlFixedSaveOptions->set_ExportFormFields(exportFormFields);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.ExportFormFields.html", htmlFixedSaveOptions);
String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.ExportFormFields.html");
if (exportFormFields)
{
outDocContents, String(u"<a name=\"CheckBox\" style=\"left:0pt; top:0pt;\"></a>") +
u"<input style=\"position:absolute; left:0pt; top:0pt;\" type=\"checkbox\" name=\"CheckBox\" />")
->get_Success());
}
else
{
ASSERT_TRUE(
outDocContents, String(u"<a name=\"CheckBox\" style=\"left:0pt; top:0pt;\"></a>") +
u"<div class=\"awdiv\" style=\"left:0.8pt; top:0.8pt; width:14.25pt; height:14.25pt; border:solid 0.75pt #000000;\"")
->get_Success());
}

◆ get_FontFormat()

Aspose::Words::Saving::ExportFontFormat Aspose::Words::Saving::HtmlFixedSaveOptions::get_FontFormat ( ) const

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

Examples

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

auto doc = MakeObject<Document>(MyDir + u"Bullet points with alternative font.docx");
auto saveOptions = MakeObject<HtmlFixedSaveOptions>();
saveOptions->set_ExportEmbeddedCss(true);
saveOptions->set_UseTargetMachineFonts(useTargetMachineFonts);
saveOptions->set_FontFormat(ExportFontFormat::Ttf);
saveOptions->set_ExportEmbeddedFonts(false);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.UsingMachineFonts.html", saveOptions);
String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.UsingMachineFonts.html");
if (useTargetMachineFonts)
{
ASSERT_FALSE(System::Text::RegularExpressions::Regex::Match(outDocContents, u"@font-face")->get_Success());
}
else
{
outDocContents, String(u"@font-face { font-family:'Arial'; font-style:normal; font-weight:normal; src:local[(]'☺'[)], ") +
u"url[(]'HtmlFixedSaveOptions.UsingMachineFonts/font001.ttf'[)] format[(]'truetype'[)]; }")
->get_Success());
}
@ Ttf
TTF (TrueType Font format).

◆ get_OptimizeOutput()

bool Aspose::Words::Saving::HtmlFixedSaveOptions::get_OptimizeOutput ( )
overridevirtual

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.

Examples

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

auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto saveOptions = MakeObject<HtmlFixedSaveOptions>();
saveOptions->set_OptimizeOutput(optimizeOutput);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.OptimizeGraphicsOutput.html", saveOptions);
// The size of the optimized version of the document is almost a third of the size of the unoptimized document.
if (optimizeOutput)
{
ASSERT_NEAR(58000, MakeObject<System::IO::FileInfo>(ArtifactsDir + u"HtmlFixedSaveOptions.OptimizeGraphicsOutput.html")->get_Length(), 200);
}
else
{
ASSERT_NEAR(161100, MakeObject<System::IO::FileInfo>(ArtifactsDir + u"HtmlFixedSaveOptions.OptimizeGraphicsOutput.html")->get_Length(), 200);
}

Reimplemented from Aspose::Words::Saving::FixedPageSaveOptions.

◆ get_PageHorizontalAlignment()

Aspose::Words::Saving::HtmlFixedPageHorizontalAlignment Aspose::Words::Saving::HtmlFixedSaveOptions::get_PageHorizontalAlignment ( ) const

Specifies the horizontal alignment of pages in an HTML document. Default value is HtmlFixedHorizontalPageAlignment.Center.

Examples

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

auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto htmlFixedSaveOptions = MakeObject<HtmlFixedSaveOptions>();
htmlFixedSaveOptions->set_PageHorizontalAlignment(pageHorizontalAlignment);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.HorizontalAlignment.html", htmlFixedSaveOptions);
String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.HorizontalAlignment/styles.css");
switch (pageHorizontalAlignment)
{
outDocContents, u"[.]awpage { position:relative; border:solid 1pt black; margin:10pt auto 10pt auto; overflow:hidden; }")
->get_Success());
break;
outDocContents, u"[.]awpage { position:relative; border:solid 1pt black; margin:10pt auto 10pt 10pt; overflow:hidden; }")
->get_Success());
break;
outDocContents, u"[.]awpage { position:relative; border:solid 1pt black; margin:10pt 10pt 10pt auto; overflow:hidden; }")
->get_Success());
break;
}
@ Center
Center pages. This is the default value.

◆ get_PageMargins()

double Aspose::Words::Saving::HtmlFixedSaveOptions::get_PageMargins ( ) const

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.

Depends on the value of PageHorizontalAlignment property:

  • Defines top, bottom and left page margins if the value is Left.
  • Defines top, bottom and right page margins if the value is Right.
  • Defines top and bottom page margins if the value is Center.
Examples

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

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
auto saveOptions = MakeObject<HtmlFixedSaveOptions>();
saveOptions->set_PageMargins(15);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.PageMargins.html", saveOptions);
String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.PageMargins/styles.css");
outDocContents, u"[.]awpage { position:relative; border:solid 1pt black; margin:15pt auto 15pt auto; overflow:hidden; }")
->get_Success());

◆ get_ResourceSavingCallback()

System::SharedPtr<Aspose::Words::Saving::IResourceSavingCallback> Aspose::Words::Saving::HtmlFixedSaveOptions::get_ResourceSavingCallback ( ) const

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

Examples

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

void HtmlFixedResourceFolder()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto callback = MakeObject<ExHtmlFixedSaveOptions::ResourceUriPrinter>();
auto options = MakeObject<HtmlFixedSaveOptions>();
options->set_SaveFormat(SaveFormat::HtmlFixed);
options->set_ExportEmbeddedImages(false);
options->set_ResourcesFolder(ArtifactsDir + u"HtmlFixedResourceFolder");
options->set_ResourcesFolderAlias(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
options->set_ShowPageBorder(false);
options->set_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.
System::IO::Directory::CreateDirectory_(options->get_ResourcesFolderAlias());
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);
std::cout << callback->GetText() << std::endl;
ArrayPtr<String> resourceFiles = System::IO::Directory::GetFiles(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
ASSERT_FALSE(System::IO::Directory::Exists(ArtifactsDir + u"HtmlFixedResourceFolder"));
std::function<bool(String f)> isImageOrCss = [](String f)
{
return f.EndsWith(u".jpeg") || f.EndsWith(u".png") || f.EndsWith(u".css");
};
ASSERT_EQ(6, resourceFiles->LINQ_Count(isImageOrCss));
}
class ResourceUriPrinter : public IResourceSavingCallback
{
public:
void ResourceSaving(SharedPtr<ResourceSavingArgs> args) override
{
// If we set a folder alias in the SaveOptions object, we will be able to print it from here.
mText->AppendLine(String::Format(u"Resource #{0} \"{1}\"", ++mSavedResourceCount, args->get_ResourceFileName()));
String extension = System::IO::Path::GetExtension(args->get_ResourceFileName());
if (extension == u".ttf" || extension == u".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->set_ResourceFileUri(ArtifactsDir + System::IO::Path::DirectorySeparatorChar + args->get_ResourceFileName());
}
mText->AppendLine(String(u"\t") + args->get_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->set_ResourceStream(MakeObject<System::IO::FileStream>(args->get_ResourceFileUri(), System::IO::FileMode::Create));
args->set_KeepResourceStreamOpen(false);
}
String GetText()
{
return mText->ToString();
}
ResourceUriPrinter() : mSavedResourceCount(0), mText(MakeObject<System::Text::StringBuilder>())
{
}
private:
int mSavedResourceCount;
SharedPtr<System::Text::StringBuilder> mText;
};

◆ get_ResourcesFolder()

System::String Aspose::Words::Saving::HtmlFixedSaveOptions::get_ResourcesFolder ( ) const

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

Has effect only if ExportEmbeddedImages property is false.

When you save a Document in Html format, Aspose.Words needs to save all images embedded in the document as standalone files. ResourcesFolder allows you to specify where the images will be saved and 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 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 ResourcesFolder property

See also
Aspose::Words::Saving::HtmlFixedSaveOptions::get_ResourcesFolderAlias
Examples

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

void HtmlFixedResourceFolder()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto callback = MakeObject<ExHtmlFixedSaveOptions::ResourceUriPrinter>();
auto options = MakeObject<HtmlFixedSaveOptions>();
options->set_SaveFormat(SaveFormat::HtmlFixed);
options->set_ExportEmbeddedImages(false);
options->set_ResourcesFolder(ArtifactsDir + u"HtmlFixedResourceFolder");
options->set_ResourcesFolderAlias(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
options->set_ShowPageBorder(false);
options->set_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.
System::IO::Directory::CreateDirectory_(options->get_ResourcesFolderAlias());
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);
std::cout << callback->GetText() << std::endl;
ArrayPtr<String> resourceFiles = System::IO::Directory::GetFiles(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
ASSERT_FALSE(System::IO::Directory::Exists(ArtifactsDir + u"HtmlFixedResourceFolder"));
std::function<bool(String f)> isImageOrCss = [](String f)
{
return f.EndsWith(u".jpeg") || f.EndsWith(u".png") || f.EndsWith(u".css");
};
ASSERT_EQ(6, resourceFiles->LINQ_Count(isImageOrCss));
}
class ResourceUriPrinter : public IResourceSavingCallback
{
public:
void ResourceSaving(SharedPtr<ResourceSavingArgs> args) override
{
// If we set a folder alias in the SaveOptions object, we will be able to print it from here.
mText->AppendLine(String::Format(u"Resource #{0} \"{1}\"", ++mSavedResourceCount, args->get_ResourceFileName()));
String extension = System::IO::Path::GetExtension(args->get_ResourceFileName());
if (extension == u".ttf" || extension == u".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->set_ResourceFileUri(ArtifactsDir + System::IO::Path::DirectorySeparatorChar + args->get_ResourceFileName());
}
mText->AppendLine(String(u"\t") + args->get_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->set_ResourceStream(MakeObject<System::IO::FileStream>(args->get_ResourceFileUri(), System::IO::FileMode::Create));
args->set_KeepResourceStreamOpen(false);
}
String GetText()
{
return mText->ToString();
}
ResourceUriPrinter() : mSavedResourceCount(0), mText(MakeObject<System::Text::StringBuilder>())
{
}
private:
int mSavedResourceCount;
SharedPtr<System::Text::StringBuilder> mText;
};

◆ get_ResourcesFolderAlias()

System::String Aspose::Words::Saving::HtmlFixedSaveOptions::get_ResourcesFolderAlias ( ) const

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

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

See also
Aspose::Words::Saving::HtmlFixedSaveOptions::get_ResourcesFolder
Examples

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

void HtmlFixedResourceFolder()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto callback = MakeObject<ExHtmlFixedSaveOptions::ResourceUriPrinter>();
auto options = MakeObject<HtmlFixedSaveOptions>();
options->set_SaveFormat(SaveFormat::HtmlFixed);
options->set_ExportEmbeddedImages(false);
options->set_ResourcesFolder(ArtifactsDir + u"HtmlFixedResourceFolder");
options->set_ResourcesFolderAlias(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
options->set_ShowPageBorder(false);
options->set_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.
System::IO::Directory::CreateDirectory_(options->get_ResourcesFolderAlias());
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);
std::cout << callback->GetText() << std::endl;
ArrayPtr<String> resourceFiles = System::IO::Directory::GetFiles(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
ASSERT_FALSE(System::IO::Directory::Exists(ArtifactsDir + u"HtmlFixedResourceFolder"));
std::function<bool(String f)> isImageOrCss = [](String f)
{
return f.EndsWith(u".jpeg") || f.EndsWith(u".png") || f.EndsWith(u".css");
};
ASSERT_EQ(6, resourceFiles->LINQ_Count(isImageOrCss));
}
class ResourceUriPrinter : public IResourceSavingCallback
{
public:
void ResourceSaving(SharedPtr<ResourceSavingArgs> args) override
{
// If we set a folder alias in the SaveOptions object, we will be able to print it from here.
mText->AppendLine(String::Format(u"Resource #{0} \"{1}\"", ++mSavedResourceCount, args->get_ResourceFileName()));
String extension = System::IO::Path::GetExtension(args->get_ResourceFileName());
if (extension == u".ttf" || extension == u".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->set_ResourceFileUri(ArtifactsDir + System::IO::Path::DirectorySeparatorChar + args->get_ResourceFileName());
}
mText->AppendLine(String(u"\t") + args->get_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->set_ResourceStream(MakeObject<System::IO::FileStream>(args->get_ResourceFileUri(), System::IO::FileMode::Create));
args->set_KeepResourceStreamOpen(false);
}
String GetText()
{
return mText->ToString();
}
ResourceUriPrinter() : mSavedResourceCount(0), mText(MakeObject<System::Text::StringBuilder>())
{
}
private:
int mSavedResourceCount;
SharedPtr<System::Text::StringBuilder> mText;
};

◆ get_SaveFontFaceCssSeparately()

bool Aspose::Words::Saving::HtmlFixedSaveOptions::get_SaveFontFaceCssSeparately ( ) const

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 ExportEmbeddedCss is false). Default value is false, all CSS rules are written into single file "styles.css".

Examples

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

auto doc = MakeObject<Document>(MyDir + u"Bookmarks.docx");
auto htmlFixedSaveOptions = MakeObject<HtmlFixedSaveOptions>();
htmlFixedSaveOptions->set_CssClassNamesPrefix(u"myprefix");
htmlFixedSaveOptions->set_SaveFontFaceCssSeparately(true);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.AddCssClassNamesPrefix.html", htmlFixedSaveOptions);
String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.AddCssClassNamesPrefix.html");
ASSERT_TRUE(
outDocContents, String(u"<div class=\"myprefixdiv myprefixpage\" style=\"width:595[.]3pt; height:841[.]9pt;\">") +
u"<div class=\"myprefixdiv\" style=\"left:85[.]05pt; top:36pt; clip:rect[(]0pt,510[.]25pt,74[.]95pt,-85.05pt[)];\">" +
u"<span class=\"myprefixspan myprefixtext001\" style=\"font-size:11pt; left:294[.]73pt; top:0[.]36pt;\">")
->get_Success());
outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.AddCssClassNamesPrefix/styles.css");
String(u".myprefixdiv { position:absolute; } ") +
u".myprefixspan { position:absolute; white-space:pre; color:#000000; font-size:12pt; }")
->get_Success());

◆ get_SaveFormat()

Aspose::Words::SaveFormat Aspose::Words::Saving::HtmlFixedSaveOptions::get_SaveFormat ( )
overridevirtual

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

Examples

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

void HtmlFixedResourceFolder()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto callback = MakeObject<ExHtmlFixedSaveOptions::ResourceUriPrinter>();
auto options = MakeObject<HtmlFixedSaveOptions>();
options->set_SaveFormat(SaveFormat::HtmlFixed);
options->set_ExportEmbeddedImages(false);
options->set_ResourcesFolder(ArtifactsDir + u"HtmlFixedResourceFolder");
options->set_ResourcesFolderAlias(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
options->set_ShowPageBorder(false);
options->set_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.
System::IO::Directory::CreateDirectory_(options->get_ResourcesFolderAlias());
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);
std::cout << callback->GetText() << std::endl;
ArrayPtr<String> resourceFiles = System::IO::Directory::GetFiles(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
ASSERT_FALSE(System::IO::Directory::Exists(ArtifactsDir + u"HtmlFixedResourceFolder"));
std::function<bool(String f)> isImageOrCss = [](String f)
{
return f.EndsWith(u".jpeg") || f.EndsWith(u".png") || f.EndsWith(u".css");
};
ASSERT_EQ(6, resourceFiles->LINQ_Count(isImageOrCss));
}
class ResourceUriPrinter : public IResourceSavingCallback
{
public:
void ResourceSaving(SharedPtr<ResourceSavingArgs> args) override
{
// If we set a folder alias in the SaveOptions object, we will be able to print it from here.
mText->AppendLine(String::Format(u"Resource #{0} \"{1}\"", ++mSavedResourceCount, args->get_ResourceFileName()));
String extension = System::IO::Path::GetExtension(args->get_ResourceFileName());
if (extension == u".ttf" || extension == u".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->set_ResourceFileUri(ArtifactsDir + System::IO::Path::DirectorySeparatorChar + args->get_ResourceFileName());
}
mText->AppendLine(String(u"\t") + args->get_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->set_ResourceStream(MakeObject<System::IO::FileStream>(args->get_ResourceFileUri(), System::IO::FileMode::Create));
args->set_KeepResourceStreamOpen(false);
}
String GetText()
{
return mText->ToString();
}
ResourceUriPrinter() : mSavedResourceCount(0), mText(MakeObject<System::Text::StringBuilder>())
{
}
private:
int mSavedResourceCount;
SharedPtr<System::Text::StringBuilder> mText;
};

Implements Aspose::Words::Saving::SaveOptions.

◆ get_ShowPageBorder()

bool Aspose::Words::Saving::HtmlFixedSaveOptions::get_ShowPageBorder ( ) const

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

Examples

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

void HtmlFixedResourceFolder()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto callback = MakeObject<ExHtmlFixedSaveOptions::ResourceUriPrinter>();
auto options = MakeObject<HtmlFixedSaveOptions>();
options->set_SaveFormat(SaveFormat::HtmlFixed);
options->set_ExportEmbeddedImages(false);
options->set_ResourcesFolder(ArtifactsDir + u"HtmlFixedResourceFolder");
options->set_ResourcesFolderAlias(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
options->set_ShowPageBorder(false);
options->set_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.
System::IO::Directory::CreateDirectory_(options->get_ResourcesFolderAlias());
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.HtmlFixedResourceFolder.html", options);
std::cout << callback->GetText() << std::endl;
ArrayPtr<String> resourceFiles = System::IO::Directory::GetFiles(ArtifactsDir + u"HtmlFixedResourceFolderAlias");
ASSERT_FALSE(System::IO::Directory::Exists(ArtifactsDir + u"HtmlFixedResourceFolder"));
std::function<bool(String f)> isImageOrCss = [](String f)
{
return f.EndsWith(u".jpeg") || f.EndsWith(u".png") || f.EndsWith(u".css");
};
ASSERT_EQ(6, resourceFiles->LINQ_Count(isImageOrCss));
}
class ResourceUriPrinter : public IResourceSavingCallback
{
public:
void ResourceSaving(SharedPtr<ResourceSavingArgs> args) override
{
// If we set a folder alias in the SaveOptions object, we will be able to print it from here.
mText->AppendLine(String::Format(u"Resource #{0} \"{1}\"", ++mSavedResourceCount, args->get_ResourceFileName()));
String extension = System::IO::Path::GetExtension(args->get_ResourceFileName());
if (extension == u".ttf" || extension == u".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->set_ResourceFileUri(ArtifactsDir + System::IO::Path::DirectorySeparatorChar + args->get_ResourceFileName());
}
mText->AppendLine(String(u"\t") + args->get_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->set_ResourceStream(MakeObject<System::IO::FileStream>(args->get_ResourceFileUri(), System::IO::FileMode::Create));
args->set_KeepResourceStreamOpen(false);
}
String GetText()
{
return mText->ToString();
}
ResourceUriPrinter() : mSavedResourceCount(0), mText(MakeObject<System::Text::StringBuilder>())
{
}
private:
int mSavedResourceCount;
SharedPtr<System::Text::StringBuilder> mText;
};

◆ get_UseTargetMachineFonts()

bool Aspose::Words::Saving::HtmlFixedSaveOptions::get_UseTargetMachineFonts ( ) const

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

Examples

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

auto doc = MakeObject<Document>(MyDir + u"Bullet points with alternative font.docx");
auto saveOptions = MakeObject<HtmlFixedSaveOptions>();
saveOptions->set_ExportEmbeddedCss(true);
saveOptions->set_UseTargetMachineFonts(useTargetMachineFonts);
saveOptions->set_FontFormat(ExportFontFormat::Ttf);
saveOptions->set_ExportEmbeddedFonts(false);
doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.UsingMachineFonts.html", saveOptions);
String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlFixedSaveOptions.UsingMachineFonts.html");
if (useTargetMachineFonts)
{
ASSERT_FALSE(System::Text::RegularExpressions::Regex::Match(outDocContents, u"@font-face")->get_Success());
}
else
{
outDocContents, String(u"@font-face { font-family:'Arial'; font-style:normal; font-weight:normal; src:local[(]'☺'[)], ") +
u"url[(]'HtmlFixedSaveOptions.UsingMachineFonts/font001.ttf'[)] format[(]'truetype'[)]; }")
->get_Success());
}

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Saving::HtmlFixedSaveOptions::GetType ( ) const
overridevirtual

◆ Is()

virtual bool Aspose::Words::Saving::HtmlFixedSaveOptions::Is ( const System::TypeInfo target) const
overridevirtual

◆ set_CssClassNamesPrefix()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_CssClassNamesPrefix ( System::String  value)

◆ set_Encoding()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_Encoding ( System::SharedPtr< System::Text::Encoding value)

◆ set_ExportEmbeddedCss()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_ExportEmbeddedCss ( bool  value)

◆ set_ExportEmbeddedFonts()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_ExportEmbeddedFonts ( bool  value)

◆ set_ExportEmbeddedImages()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_ExportEmbeddedImages ( bool  value)

◆ set_ExportEmbeddedSvg()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_ExportEmbeddedSvg ( bool  value)

◆ set_ExportFormFields()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_ExportFormFields ( bool  value)

◆ set_FontFormat()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_FontFormat ( Aspose::Words::Saving::ExportFontFormat  value)

◆ set_OptimizeOutput()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_OptimizeOutput ( bool  value)
overridevirtual

◆ set_PageHorizontalAlignment()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_PageHorizontalAlignment ( Aspose::Words::Saving::HtmlFixedPageHorizontalAlignment  value)

◆ set_PageMargins()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_PageMargins ( double  value)

◆ set_ResourceSavingCallback()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_ResourceSavingCallback ( System::SharedPtr< Aspose::Words::Saving::IResourceSavingCallback value)

◆ set_ResourcesFolder()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_ResourcesFolder ( System::String  value)

◆ set_ResourcesFolderAlias()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_ResourcesFolderAlias ( System::String  value)

◆ set_SaveFontFaceCssSeparately()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_SaveFontFaceCssSeparately ( bool  value)

◆ set_SaveFormat()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_SaveFormat ( Aspose::Words::SaveFormat  value)
overridevirtual

◆ set_ShowPageBorder()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_ShowPageBorder ( bool  value)

◆ set_UseTargetMachineFonts()

void Aspose::Words::Saving::HtmlFixedSaveOptions::set_UseTargetMachineFonts ( bool  value)

◆ Type()

static const System::TypeInfo& Aspose::Words::Saving::HtmlFixedSaveOptions::Type ( )
static