windowsforms-3240-controls-and-libraries-printing-exporting-examples-exporting-how-to-export-a-document-to-html.md
The following example demonstrates how to export a Printing System document to HTML format. To do this, the PrintingSystemBase.ExportToHtml method should be used. It also demonstrates what specific HtmlExportOptions may be used when a document is exported to HTML.
For this example to work, you first need to add a PrintingSystem component (named printingSystem1) to your project, and then execute the code below (for instance, in the Button.Click event handler of any button on a form). Also note that if you want the resulting file to be automatically opened in the default program which is used to open *.html files in your system, you can call the StartProcess method, which is also shown in this example.
using System.Drawing;
using System.Diagnostics;
using DevExpress.XtraPrinting;
// ...
private void button1_Click(object sender, EventArgs e)
{
// A path to export a document.
string documentPath = "c:\\Test.html";
// Get HTML export options.
HtmlExportOptions htmlOptions = printingSystem1.ExportOptions.Html;
// Set HTML-specific export options.
htmlOptions.CharacterSet = "UTF-8";
htmlOptions.RemoveSecondarySymbols = false;
htmlOptions.Title = "Test Title";
// Set the pages to be exported, and page-by-page options.
htmlOptions.ExportMode = HtmlExportMode.SingleFilePageByPage;
htmlOptions.PageRange = "1, 3-5";
htmlOptions.PageBorderColor = Color.Blue;
htmlOptions.PageBorderWidth = 3;
// Export the document to HTML.
printingSystem1.ExportToHtml(documentPath);
// Show the result.
StartProcess(documentPath);
}
// Use this method if you want to automaically open
// the created HTML file in the default program.
public void StartProcess(string path)
{
Process process = new Process();
try
{
process.StartInfo.FileName = path;
process.Start();
process.WaitForInputIdle();
}
catch { }
}
Imports System.Drawing
Imports System.Diagnostics
Imports DevExpress.XtraPrinting
' ...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
' A path to export a document.
Dim documentPath As String = "c:\\Test.html"
' Get HTML export options.
Dim htmlOptions As HtmlExportOptions = printingSystem1.ExportOptions.Html
' Set HTML-specific export options.
htmlOptions.CharacterSet = "UTF-8"
htmlOptions.RemoveSecondarySymbols = False
htmlOptions.Title = "Test Title"
' Set the pages to be exported, and page-by-page options.
htmlOptions.ExportMode = HtmlExportMode.SingleFilePageByPage
htmlOptions.PageRange = "1, 3-5"
htmlOptions.PageBorderColor = Color.Blue
htmlOptions.PageBorderWidth = 3
' Export the document to HTML.
printingSystem1.ExportToHtml(documentPath)
' Show the result.
StartProcess(documentPath)
End Sub
' Use this method if you want to automaically open
' the created HTML file in the default program.
Public Sub StartProcess(ByVal path As String)
Dim process As New Process()
Try
process.StartInfo.FileName = path
process.Start()
process.WaitForInputIdle()
Catch
End Try
End Sub
See Also
How to: Customize How a Document Is Exported from the Print Preview