PdfMetamorphosisHtmlToPdfConvertFile Method |
Converts HTML file or URL to PDF file. Output file will be overwritten.
Namespace: SautinSoftAssembly: PdfMetamorphosis (in PdfMetamorphosis.dll) Version: 2025.2.25
Syntaxpublic 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
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
ExampleHow 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();
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)
Dim p As New SautinSoft.PdfMetamorphosis()
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