Saves a specific PDF page or diapason of pages to HTML document and returns it as string

Namespace:  SautinSoft
Assembly:  SautinSoft.PdfFocus (in SautinSoft.PdfFocus.dll) Version: 6.6.9.7 (6.6.9.7)

Syntax

      
 C#  Visual Basic 
public string ToHtml(
	int fromPage,
	int toPage
)
Public Function ToHtml ( _
	fromPage As Integer, _
	toPage As Integer _
) As String

Parameters

fromPage
Int32
The starting page for exporting to HTML
toPage
Int32
The ending page for exporting to HTML

Return Value

String with HTML document - in case of converting successful.
null - in case of converting failed.

Examples

CopyHow to convert PDF to separate HTML pages in C#
using System;
using System.IO;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            // Convert PDF to separate HTMLs.
            // Each PDF page will be converted to a single HTML document.

            // Path to PDF file.
            string pdfPath = Path.GetFullPath(@"..\..\..\..\..\simple text.pdf");

            // Directory to store HTML documents.
            string htmlDir = Path.GetDirectoryName(pdfPath);

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            f.HtmlOptions.IncludeImageInHtml = false;
            // Path (must exist) to a directory to store images after converting. Notice also to the property "ImageSubFolder".
            f.HtmlOptions.ImageFolder = htmlDir;

            f.OpenPdf(pdfPath);

            // Convert each PDF page to separate HTML document.
            // simple text.html, simple text.html ... simple text.html.
            for (int page = 1; page <= f.PageCount; page++)
            {
                f.HtmlOptions.Title = String.Format("Simple Text - Page {0}", page);
                f.HtmlOptions.ImageSubFolder = String.Format("images-page{0}", page);
                string htmlString = f.ToHtml(page, page);

                // Save htmlString to file
                string htmlPath = Path.Combine(htmlDir, String.Format("Page{0}.html", page));
                File.WriteAllText(htmlPath, htmlString);

                // Let's show first and last HTML pages.
                if (page == 1 || page==f.PageCount)
                    System.Diagnostics.Process.Start(htmlPath);
            }

        }
    }
}
CopyHow to convert PDF to separate HTML pages in VB.Net
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft

Module Sample

    Sub Main()
        ' Convert PDF to separate HTMLs.
        ' Each PDF page will be converted to a single HTML document.


        ' Path to PDF file.
        Dim pdfPath As String = Path.GetFullPath("..\..\..\..\simple text.pdf")

        ' Directory to store HTML documents.
        Dim htmlDir As String = Path.GetDirectoryName(pdfPath)

        Dim f As New SautinSoft.PdfFocus()

        f.HtmlOptions.IncludeImageInHtml = False
        ' Path (must exist) to a directory to store images after converting. Notice also to the property "ImageSubFolder".
        f.HtmlOptions.ImageFolder = htmlDir

        f.OpenPdf(pdfPath)

        ' Convert each PDF page to separate HTML document.
        ' simple text.html, simple text.html ... simple text.html.
        For page As Integer = 1 To f.PageCount
            f.HtmlOptions.Title = String.Format("Simple Text - Page {0}", page)
            f.HtmlOptions.ImageSubFolder = String.Format("images-page{0}", page)
            Dim htmlString As String = f.ToHtml(page, page)

            ' Save htmlString to file
            Dim htmlPath As String = Path.Combine(htmlDir, String.Format("Page{0}.html", page))
            File.WriteAllText(htmlPath, htmlString)

            ' Let's show first and last HTML pages.
            If page = 1 OrElse page = f.PageCount Then
                System.Diagnostics.Process.Start(htmlPath)
            End If
        Next page
    End Sub
End Module

See Also