PdfFocusToHtml(Int32, Int32) Method |
Saves a specific PDF page or diapason of pages to HTML document as string object.
Namespace: SautinSoftAssembly: SautinSoft.PdfFocus (in SautinSoft.PdfFocus.dll) Version: 2024.12.2
Syntax public string ToHtml(
int fromPage,
int toPage
)
Public Function ToHtml (
fromPage As Integer,
toPage As Integer
) As String
Parameters
- fromPage Int32
- The starting page to export into HTML.
- toPage Int32
- The ending page to export into HTML.
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 separate HTML pages in C#
using System;
using System.IO;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
string pdfFile = Path.GetFullPath(@"..\..\..\simple text.pdf");
DirectoryInfo htmlDir = new DirectoryInfo("htmls");
if (!htmlDir.Exists)
htmlDir.Create();
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.HtmlOptions.IncludeImageInHtml = false;
f.HtmlOptions.ImageFolder = htmlDir.FullName;
f.OpenPdf(pdfFile);
if (f.PageCount > 0)
{
for (int page = 1; page <= f.PageCount; page++)
{
f.HtmlOptions.Title = $"Page {page}";
f.HtmlOptions.ImageSubFolder = String.Format("page{0}_images", page);
string htmlString = f.ToHtml(page, page);
string htmlFile = Path.Combine(htmlDir.FullName, $"Page{page}.html");
File.WriteAllText(htmlFile, htmlString);
if (page == 1 || page == f.PageCount)
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(htmlFile) { UseShellExecute = true });
}
}
}
}
}
}
How to convert PDF to separate HTML pages in VB.Net
Imports System
Imports System.IO
Namespace Sample
Friend Class Sample
Shared Sub Main(ByVal args() As String)
Dim pdfFile As String = Path.GetFullPath("..\..\..\simple text.pdf")
Dim htmlDir As New DirectoryInfo("htmls")
If Not htmlDir.Exists Then
htmlDir.Create()
End If
Dim f As New SautinSoft.PdfFocus()
f.HtmlOptions.IncludeImageInHtml = False
f.HtmlOptions.ImageFolder = htmlDir.FullName
f.OpenPdf(pdfFile)
If f.PageCount > 0 Then
For page As Integer = 1 To f.PageCount
f.HtmlOptions.Title = $"Page {page}"
f.HtmlOptions.ImageSubFolder = String.Format("page{0}_images", page)
Dim htmlString As String = f.ToHtml(page, page)
Dim htmlFile As String = Path.Combine(htmlDir.FullName, $"Page{page}.html")
File.WriteAllText(htmlFile, htmlString)
If page = 1 OrElse page = f.PageCount Then
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(htmlFile) With {.UseShellExecute = True})
End If
Next page
End If
End Sub
End Class
End Namespace
See Also