HtmlToPdfOptionsFooter Property |
Footer in HTML format. Default: String.Empty. Should be valid HTML markup with following classes used to inject printing values into them:
date - formatted print date
title - document title
url - document location
pageNumber - current page number
totalPages - total pages in the document
Namespace: SautinSoft.PdfVisionAssembly: SautinSoft.PdfVision (in SautinSoft.PdfVision.dll) Version: 2024.12.6
Syntax public string Footer { get; set; }
Public Property Footer As String
Get
Set
Property Value
StringExample Add Header and Footer using C#
using System;
using System.IO;
using SautinSoft.PdfVision;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
AddHeaderAndFooter();
}
public static void AddHeaderAndFooter()
{
string inpFile = Path.GetFullPath(@"..\..\..\Sample.html");
string outFile = new FileInfo("Result.pdf").FullName;
PdfVision v = new PdfVision();
HtmlToPdfOptions options = new HtmlToPdfOptions()
{
PageSetup = new PageSetup()
{
PaperType = PaperType.Letter,
Orientation = Orientation.Portrait,
PageMargins = new PageMargins()
{
Left = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
Top = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
Right = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
Bottom = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter)
}
},
PrintBackground = true,
Scale = 1,
ChromiumBaseDirectory = Path.GetFullPath(@"..\..\..\..\..\..\Chromium\")
};
options.PageSetup.PageMargins.Top += LengthUnitConverter.ToPoint(40, LengthUnit.Millimeter);
string imgPath = @"..\..\..\logo.png";
string imgBase64Encoded = Convert.ToBase64String(File.ReadAllBytes(imgPath));
string header = "<div style=\"border: solid 0.5pt grey; width: 100%; display: flex; justify-content: flex-start; align-items: center; margin: 5px; padding: 0; \">" +
$"<img style=\"width: 96px; height: 96px; margin: 0;\" src=\"data:image/png;base64,{imgBase64Encoded}\" />" +
"<div style=\"width: calc(100% -300px - 50px); height: 96px; margin: 0; padding: 0; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start;\">" +
"<h1 style=\"width: 100%; margin: 0; padding-left: 10px; font-family: \'Arial\', sans-serif; color: gray; font-size: 24px; font-weight: bold; text-align: left; \">" +
"PDF Vision .Net</h1>" +
"<p style=\"margin: 0; padding-left: 10px; font-family: \'Arial\', sans-serif; color: #000; font-size: 18px; font-weight: normal; text-align: left;\">" +
"Gives your apps API to convert ASPX, HTML, Images (Multipage TIFF, PNG, Jpeg, Bitmap) to PDF." +
"</p></div>" +
"<div style=\"width: 100px; margin: 0; padding-top: 5px; padding-right: 5px; align-self: flex-start; display: flex; justify-content: flex-end; font-family: \'Arial\', sans-serif; color: #ccc; font-size: 10px; font-weight: bold;\">" +
"<div>Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>" +
"</div></div>";
options.Header = header;
options.PageSetup.PageMargins.Bottom += LengthUnitConverter.ToPoint(20, LengthUnit.Millimeter);
string footer = "<div style=\"font-family: \'Arial\', sans-serif; color: #ccc; font-size: 18px; margin: 0 auto;\">Simple page footer aligned by center.</div>";
options.Footer = footer;
try
{
v.ConvertHtmlToPdf(inpFile, outFile, options);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
Console.ReadLine();
}
}
}
}
Add Header and Footer using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.PdfVision
Namespace Sample
Friend Class Program
Shared Sub Main(ByVal args() As String)
AddHeaderAndFooter()
End Sub
Public Shared Sub AddHeaderAndFooter()
Dim inpFile As String = Path.GetFullPath("..\..\..\Sample.html")
Dim outFile As String = (New FileInfo("Result.pdf")).FullName
Dim v As New PdfVision()
Dim options As New HtmlToPdfOptions() With {
.PageSetup = New PageSetup() With {
.PaperType = PaperType.Letter,
.Orientation = Orientation.Portrait,
.PageMargins = New PageMargins() With {
.Left = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
.Top = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
.Right = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
.Bottom = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter)
}
},
.PrintBackground = True,
.Scale = 1,
.ChromiumBaseDirectory = Path.GetFullPath("..\..\..\..\..\..\Chromium\")
}
options.PageSetup.PageMargins.Top += LengthUnitConverter.ToPoint(40, LengthUnit.Millimeter)
Dim imgPath As String = "..\..\..\logo.png"
Dim imgBase64Encoded As String = Convert.ToBase64String(File.ReadAllBytes(imgPath))
Dim header As String = "<div style=""border: solid 0.5pt grey; width: 100%; display: flex; justify-content: flex-start; align-items: center; margin: 5px; padding: 0; "">" & $"<img style=""width: 96px; height: 96px; margin: 0;"" src=""data:image/png;base64,{imgBase64Encoded}"" />" & "<div style=""width: calc(100% -300px - 50px); height: 96px; margin: 0; padding: 0; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start;"">" & "<h1 style="">" & "PDF Vision .Net</h1>" & "<p style="">" & "Gives your apps API to convert ASPX, HTML, Images (Multipage TIFF, PNG, Jpeg, Bitmap) to PDF." & "</p></div>" & "<div style="">" & "<div>Page <span class=""pageNumber""></span> of <span class=""totalPages""></span></div>" & "</div></div>"
options.Header = header
options.PageSetup.PageMargins.Bottom += LengthUnitConverter.ToPoint(20, LengthUnit.Millimeter)
Dim footer As String = "<div style="">Simple page footer aligned by center.</div>"
options.Footer = footer
Try
v.ConvertHtmlToPdf(inpFile, outFile, options)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
Catch ex As Exception
Console.WriteLine($"Error: {ex.Message}")
Console.ReadLine()
End Try
End Sub
End Class
End Namespace
See Also