Converts HTML file or URL to PDF file. Output file will be overwritten.

Namespace:  SautinSoft
Assembly:  PdfMetamorphosis (in PdfMetamorphosis.dll) Version: 5.3.4.18

Syntax

      
 C#  Visual Basic 
public int HtmlToPdfConvertFile(
	string inputFileName,
	string outputFileName
)
Public Function HtmlToPdfConvertFile ( _
	inputFileName As String, _
	outputFileName As String _
) As Integer

Parameters

inputFileName
String
Path to local HTML file or URL
outputFileName
String
Local path to output PDF file

Return Value

0 - converting successfully
1 - can't open input HTML file, check the input path
2 - can't create output file, check the output path
3 - converting failed

Examples

CopyHow to convert HTML file to PDF file in C#
using System;
using System.IO;
using System.Collections;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {

            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
            //this property is necessary only for registered version
            //p.Serial = "XXXXXXXXXXX";

            //specify some options
            p.PageStyle.PageOrientation.Landscape();
            //specify header in HTML format
            p.Header.Html("<b>Sample header in HTML format</b>");

            //specify footer in RTF format
            p.Footer.Rtf("{\b Bold footer}");


            p.PageStyle.PageNumFormat = "Page {page} of {numpages}";

            if (p != null)
            {
                string inputFile = @"..\..\..\..\..\test.htm";
                string outputFile = @"..\..\..\..\..\test.pdf";

                int result = p.HtmlToPdfConvertFile(inputFile, outputFile);

                if (result == 0)
                {
                    System.Console.WriteLine("Converted successfully!");
                    System.Diagnostics.Process.Start(outputFile);
                }
                else
                {
                    System.Console.WriteLine("Converting Error!");
                }
            }
        }
    }
}
CopyHow to convert HTML file to PDF file in VB.Net
Imports System
Imports System.IO
Imports System.Text

Module sample

    Sub Main()
        Dim p As New SautinSoft.PdfMetamorphosis
        'this property is necessary only for registered version
        'p.Serial = "XXXXXXXXXXX";


        'specify some options
        p.PageStyle.PageOrientation.Landscape()
        'specify header in HTML format
        p.Header.Html("<b>Sample header in HTML format</b>")

        'specify footer in RTF format
        p.Footer.Rtf("{\b Bold footer}")


        p.PageStyle.PageNumFormat = "Page {page} of {numpages}"

        If Not p Is Nothing Then
            Dim inputFile As String = "..\..\..\..\..\test.htm"
            Dim outputFile As String = "..\..\..\..\..\test.pdf"

            Dim result As Integer = p.HtmlToPdfConvertFile(inputFile, outputFile)

            If result = 0 Then
                System.Console.WriteLine("Converted successfully!")
                System.Diagnostics.Process.Start(outputFile)
            Else
                System.Console.WriteLine("Converting Error!")
            End If
        End If
    End Sub
End Module

See Also