Gets or sets the top margin (in points).
Namespace: SautinSoft.PdfVisionAssembly: SautinSoft.PdfVision (in SautinSoft.PdfVision.dll) Version: 2024.12.6
Syntax public double Top { get; set; }
Public Property Top As Double
Get
Set
Property Value
DoubleExample Add Page Numbering using C#
using System;
using System.IO;
using SautinSoft.PdfVision;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
AddPageNumbering();
}
public static void AddPageNumbering()
{
string inpFile = File.ReadAllText(@"..\..\..\example.html");
string outFile = new FileInfo("Result.pdf").FullName;
PdfVision v = new PdfVision();
HtmlToPdfOptions options = new HtmlToPdfOptions()
{
PageSetup = new PageSetup()
{
PaperType = PaperType.Letter,
Orientation = Orientation.Landscape,
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(20, LengthUnit.Millimeter);
string headerWithNumbering = "<div style=\"font-size: 18pt; font-family: Sans-serif;" +
"color: #0d6efd; margin: 0px auto;\">" +
"Page <span class=\"pageNumber\"></span> of " +
"<span class=\"totalPages\"></span><div>";
options.Header = headerWithNumbering;
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 Page Numbering using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.PdfVision
Namespace Sample
Friend Class Program
Shared Sub Main(ByVal args() As String)
AddPageNumbering()
End Sub
Public Shared Sub AddPageNumbering()
Dim inpFile As String = File.ReadAllText("..\..\..\example.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.Landscape,
.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 = 1D,
.ChromiumBaseDirectory = Path.GetFullPath("..\..\..\..\..\..\Chromium\")
}
options.PageSetup.PageMargins.Top += LengthUnitConverter.ToPoint(20, LengthUnit.Millimeter)
Dim headerWithNumbering As String = "<div style=""font-size: 18pt; font-family: Sans-serif;" & "color: #0d6efd; margin: 0px auto;"">" & "Page <span class=""pageNumber""></span> of " & "<span class=""totalPages""></span><div>"
options.Header = headerWithNumbering
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