Click or drag to resize

PdfMetamorphosisHtmlToPdfConvertFile Method

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

Namespace: SautinSoft
Assembly: PdfMetamorphosis (in PdfMetamorphosis.dll) Version: 2024.1.12
Syntax
public int HtmlToPdfConvertFile(
	string inputFileName,
	string outputFileName
)

Parameters

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

Return Value

Int32
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
Example
How 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)
        {    
            // Activate your license here
            // SautinSoft.PdfMetamorphosis.SetLicense("1234567890");

            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();

            //specify some options
            p.PageSettings.Size.A4();
            p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape;
            p.PageSettings.Numbering.Text = "Page {page} of {numpages}";

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

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

                if (result == 0)
                {
                    System.Console.WriteLine("Converted successfully!");
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outputFile) { UseShellExecute = true });
                }
                else
                {
                    System.Console.WriteLine("Converting Error!");
                }
            }
        }
    }
}
How to convert HTML file to PDF file in VB.Net
Namespace Sample
    Friend Class Test

        Shared Sub Main(ByVal args() As String)
                ' Activate your license here
                ' SautinSoft.PdfMetamorphosis.SetLicense("1234567890")

            Dim p As New SautinSoft.PdfMetamorphosis()

            'specify some options
            p.PageSettings.Size.A4()
            p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape

            p.PageSettings.Numbering.Text = "Page {page} of {numpages}"

            If p IsNot Nothing Then
                Dim inputFile As String = "..\..\..\example.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(New System.Diagnostics.ProcessStartInfo(outputFile) With {.UseShellExecute = True})
                Else
                    System.Console.WriteLine("Converting Error!")
                End If
            End If
        End Sub
    End Class
End Namespace
See Also