PrettyFormat
Contents
[
Hide
]SaveOptions.PrettyFormat property
When true
, pretty formats output where applicable. Default value is false
.
public bool PrettyFormat { get; set; }
Remarks
Set to true
to make HTML, MHTML, EPUB, WordML, RTF, DOCX and ODT output human readable. Useful for testing or debugging.
Examples
Shows how to enhance the readability of the raw code of a saved .html document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello world!");
HtmlSaveOptions htmlOptions = new HtmlSaveOptions(SaveFormat.Html) { PrettyFormat = usePrettyFormat };
doc.Save(ArtifactsDir + "HtmlSaveOptions.PrettyFormat.html", htmlOptions);
// Enabling pretty format makes the raw html code more readable by adding tab stop and new line characters.
string html = File.ReadAllText(ArtifactsDir + "HtmlSaveOptions.PrettyFormat.html");
if (usePrettyFormat)
Assert.AreEqual(
"<html>\r\n" +
"\t<head>\r\n" +
"\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n" +
"\t\t<meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />\r\n" +
$"\t\t<meta name=\"generator\" content=\"{BuildVersionInfo.Product} {BuildVersionInfo.Version}\" />\r\n" +
"\t\t<title>\r\n" +
"\t\t</title>\r\n" +
"\t</head>\r\n" +
"\t<body style=\"font-family:'Times New Roman'; font-size:12pt\">\r\n" +
"\t\t<div>\r\n" +
"\t\t\t<p style=\"margin-top:0pt; margin-bottom:0pt\">\r\n" +
"\t\t\t\t<span>Hello world!</span>\r\n" +
"\t\t\t</p>\r\n" +
"\t\t\t<p style=\"margin-top:0pt; margin-bottom:0pt\">\r\n" +
"\t\t\t\t<span style=\"-aw-import:ignore\"> </span>\r\n" +
"\t\t\t</p>\r\n" +
"\t\t</div>\r\n" +
"\t</body>\r\n</html>",
html);
else
Assert.AreEqual(
"<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" +
"<meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />" +
$"<meta name=\"generator\" content=\"{BuildVersionInfo.Product} {BuildVersionInfo.Version}\" /><title></title></head>" +
"<body style=\"font-family:'Times New Roman'; font-size:12pt\">" +
"<div><p style=\"margin-top:0pt; margin-bottom:0pt\"><span>Hello world!</span></p>" +
"<p style=\"margin-top:0pt; margin-bottom:0pt\"><span style=\"-aw-import:ignore\"> </span></p></div></body></html>",
html);
See Also
- class SaveOptions
- namespace Aspose.Words.Saving
- assembly Aspose.Words