PdfMetamorphosisHeadersFootersFromFile(String, PdfMetamorphosisHeadersFootersInputFormat) Method |
Set header/footer from any DOCX, DOC, RTF, HTML or Text file.
Namespace: SautinSoftAssembly: PdfMetamorphosis (in PdfMetamorphosis.dll) Version: 2024.12.3
Syntax public void FromFile(
string path,
PdfMetamorphosisHeadersFootersInputFormat inputFormat
)
Public Sub FromFile (
path As String,
inputFormat As PdfMetamorphosisHeadersFootersInputFormat
)
Parameters
- path String
- Path to local file.
- inputFormat PdfMetamorphosisHeadersFootersInputFormat
- Allows you to specify the input format for header and footer.
Remarks We don't recommend to use it for complex HTML documents as header or footer. The best is using simple HTML table with text and images as header/footer.
Example How to add page header and footer using C#.
using System.IO;
namespace Sample
{
class Test
{
static void Main(string[] args)
{
SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
string headerInHtml = "<table width=\"100%\" border=\"0\" style=\"border-collapse: collapse\"><tr><td style=\"border: 1pt solid black\" ></td><td width=\"50%\" align=\"center\" style=\"border: 1pt solid black\">You are welcome!</td></tr></table>";
p.PageSettings.Header.FromString(headerInHtml, SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html);
string footerInRtf = @"{\rtf1\i Italic footer }";
p.PageSettings.Footer.FromString(footerInRtf, SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Rtf);
if (p != null)
{
string inputFile = @"..\..\..\example.htm";
string outputFile = Path.ChangeExtension(inputFile, ".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 add page header and footer using VB.Net.
Module sample
Sub Main()
Dim p As New SautinSoft.PdfMetamorphosis()
Dim headerInHtml As String = "<table width=\"100%\" border=\"0\" style=\"border-collapse: collapse\"><tr><td style=\"border: 1pt solid black\" ></td><td width=\"50%\" align=\"center\" style=\"border: 1pt solid black\">You are welcome!</td></tr></table>"
p.PageSettings.Header.FromString(headerInHtml, SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html)
Dim footerInRtf As String = "{\rtf1\i Italic Footer}"
p.PageSettings.Footer.FromString(footerInRtf, SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Rtf)
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 Module
See Also