Saves all pages of the PDF document into HTML document as string object.
Namespace: SautinSoftAssembly: SautinSoft.PdfFocus (in SautinSoft.PdfFocus.dll) Version: 2024.11.11
Syntax Public Function ToHtml As String
Return Value
String
HTML document as String object - in case of converting successfully.
null - in case of converting failed.
Example How to convert PDF to HTML in memory using C#
using System;
using System.IO;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
ConvertPdfBytesToHtml();
}
private static void ConvertPdfBytesToHtml()
{
string pdfFile = Path.GetFullPath(@"..\..\..\simple text.pdf");
string htmlFile = "Result.html";
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.HtmlOptions.IncludeImageInHtml = true;
f.HtmlOptions.Title = "Simple text";
byte[] pdf = File.ReadAllBytes(pdfFile);
f.OpenPdf(pdf);
if (f.PageCount > 0)
{
string html = f.ToHtml();
if (html != null)
{
File.WriteAllText(htmlFile, html);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(htmlFile) { UseShellExecute = true });
}
}
}
private static void ConvertPdfStreamToHtml()
{
string pdfFile = Path.GetFullPath(@"..\..\..\simple text.pdf");
string htmlFile = "Result.html";
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.HtmlOptions.IncludeImageInHtml = true;
f.HtmlOptions.Title = "Simple text";
using (FileStream fs = File.OpenRead(pdfFile))
{
f.OpenPdf(fs);
if (f.PageCount > 0)
{
using (MemoryStream msHtml = new MemoryStream())
{
int res = f.ToHtml(msHtml);
if (res == 0)
{
File.WriteAllBytes(htmlFile, msHtml.ToArray());
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(htmlFile) { UseShellExecute = true });
}
}
}
}
}
}
}
How to convert PDF to HTML in memory using VB.Net
Imports System
Imports System.IO
Namespace Sample
Friend Class Sample
Shared Sub Main(ByVal args() As String)
ConvertPdfBytesToHtml()
End Sub
Private Shared Sub ConvertPdfBytesToHtml()
Dim pdfFile As String = Path.GetFullPath("..\..\..\simple text.pdf")
Dim htmlFile As String = "Result.html"
Dim f As New SautinSoft.PdfFocus()
f.HtmlOptions.IncludeImageInHtml = True
f.HtmlOptions.Title = "Simple text"
Dim pdf() As Byte = File.ReadAllBytes(pdfFile)
f.OpenPdf(pdf)
If f.PageCount > 0 Then
Dim html As String = f.ToHtml()
If html IsNot Nothing Then
File.WriteAllText(htmlFile, html)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(htmlFile) With {.UseShellExecute = True})
End If
End If
End Sub
Private Shared Sub ConvertPdfStreamToHtml()
Dim pdfFile As String = Path.GetFullPath("..\..\..\simple text.pdf")
Dim htmlFile As String = "Result.html"
Dim f As New SautinSoft.PdfFocus()
f.HtmlOptions.IncludeImageInHtml = True
f.HtmlOptions.Title = "Simple text"
Using fs As FileStream = File.OpenRead(pdfFile)
f.OpenPdf(fs)
If f.PageCount > 0 Then
Using msHtml As New MemoryStream()
Dim res As Integer = f.ToHtml(msHtml)
If res = 0 Then
File.WriteAllBytes(htmlFile, msHtml.ToArray())
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(htmlFile) With {.UseShellExecute = True})
End If
End Using
End If
End Using
End Sub
End Class
End Namespace
See Also