HtmlToRtfConvert(Byte, Byte, HtmlToRtfHtmlConvertOptions) Method |
Converts HTML to DOCX, RTF or Text documents using byte arrays.
Namespace: SautinSoftAssembly: SautinSoft.HtmlToRtf (in SautinSoft.HtmlToRtf.dll) Version: 2024.12.12
Syntax public bool Convert(
byte[] inpHtml,
out byte[] outDocument,
HtmlToRtfHtmlConvertOptions opt
)
Public Function Convert (
inpHtml As Byte(),
<OutAttribute> ByRef outDocument As Byte(),
opt As HtmlToRtfHtmlConvertOptions
) As Boolean
Parameters
- inpHtml Byte
- Input HTML document as array of bytes.
- outDocument Byte
- DOCX, RTF or Text document as array of bytes.
- opt HtmlToRtfHtmlConvertOptions
- Options to control HTML converting and adjust the output document.
Return Value
BooleanReturns true in case of converting successfully, otherwise false.
In case of false, see
ExceptionList to find more information about the issues.
Example Convert HTML to DOCX bytes using C#
using System;
using System.IO;
using SautinSoft;
namespace Sample
{
class Test
{
static void Main(string[] args)
{
ConvertHtmlToDocxBytes();
}
public static void ConvertHtmlToDocxBytes()
{
SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();
string inputFile = @"..\..\..\pic.html";
string outputFile = "Result.docx";
byte[] htmlBytes = File.ReadAllBytes(inputFile);
byte[] docxBytes = null;
if (h.Convert(htmlBytes, out docxBytes, new HtmlToRtf.HtmlConvertOptions() { OutputFormat = HtmlToRtf.OutputFormat.Docx, BaseURL = Path.GetDirectoryName(inputFile) }))
{
File.WriteAllBytes(outputFile, docxBytes);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outputFile) { UseShellExecute = true });
}
}
}
}
Convert HTML to DOCX bytes using VB.Net
Imports System
Imports System.IO
Imports SautinSoft
Imports SautinSoft.HtmlToRtf
Namespace Sample
Friend Class Test
Shared Sub Main(ByVal args() As String)
ConvertHtmlToDocxBytes()
End Sub
Public Shared Sub ConvertHtmlToDocxBytes()
Dim h As New SautinSoft.HtmlToRtf()
Dim inputFile As String = "..\..\..\pic.html"
Dim outputFile As String = "Result.docx"
Dim htmlBytes() As Byte = File.ReadAllBytes(inputFile)
Dim docxBytes() As Byte = Nothing
Dim opt As New HtmlConvertOptions()
opt.BaseURL = Path.GetDirectoryName(Path.GetFullPath(inputFile))
opt.OutputFormat = HtmlToRtf.OutputFormat.Docx
If h.Convert(htmlBytes, docxBytes, opt) Then
File.WriteAllBytes(outputFile, docxBytes)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outputFile) With {.UseShellExecute = True})
End If
End Sub
End Class
End Namespace
See Also