Using VB.NET PDF Library
How to count, show page numbers in PDF using VB .NET in Windows Forms, ASP.NET app
VB.NET Demo Code to count and display PDF page number in Visual Basic .NET
In this vb tutorial, you will learn how to count PDF total pages number, and show current page number with total page count on PDF page header and footer in Visual Basic .NET
- Get PDF document total pages number
- Show, display page number and total page count on each PDF page
- Easy to show page number in VB.NET Windows Forms, WPF applications
- Complete C# tutorial source code at How to count PDF page number using C#
How to count, show PDF page number programmatically using VB.NET
asp.net open excel file on client,
asp.net pdf viewer control free,
show image in asp.net core mvc,
best pdf preview in asp net c#,
asp net remove image from pdf,
asp.net mvc pdf editor,
mvc view to pdf itextsharp.
VB.NET: How to count the total number of PDF pages using VB code
It is simply to count the total pages number of PDF in VB.NET. Below are the steps and VB.NET sample code to count the PDF document total pages number.
- Create a PDFDocument object with a PDF file loaded
- Call method GetPageCount to get the total page number of PDF document
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
int pageCount = doc.GetPageCount();
Console.WriteLine("Page Count: " + pageCount);
VB.NET: How to get and show page number in PDF using VB code
You can get current PDF page number and total pages count displayed in the page header or footer.
For Automatic Page Number
- <<1>> : Page number only.
- <<1/n>> : Page number and total page count, with separator '/'.
Using Visual Basic .NET, you can easily display current page number and pdf total pages count on PDF header and footer in vb.net code.
Below are the steps and VB.NET demo source code to show page number and total pages count of PDF file.
- Create a PDFDocument object with a PDF file loaded
- Create a new PDFPageHeaderFooter object
- Add current page footer and total pages count on the page footer
- Save the PDF file with page header footer applied
Dim inputFilePath As String = "C:\1.pdf"
Dim outputFilePath As String = "C:\1_hdrftr.pdf"
' open a PDF file
Dim doc As PDFDocument = New PDFDocument(inputFilePath)
' define a header/footer setting
Dim hdrftr1 As PDFPageHeaderFooter = New PDFPageHeaderFooter()
' set center header field
hdrftr1.CenterHeaderField.Set("Title: *****", New Font("Arial", 12.0F, FontStyle.Regular), Color.Black)
' set left footer field
hdrftr1.LeftFooterField.Set("Page <<1/n>>", New Font("Arial", 9.0F, FontStyle.Regular), Color.DarkGray)
' define page range all odd pages
Dim pageRange1 As PageRangeOptions = New PageRangeOptions()
pageRange1.AllPages = True
pageRange1.Subset = PageRangeSubset.Odd
' apply header/footer settings to all odd pages
PDFPageFieldHandler.ApplyHeaderFooter(doc, hdrftr1, pageRange1)
' define a header/footer setting
Dim hdrftr2 As PDFPageHeaderFooter = New PDFPageHeaderFooter()
' set center header field
hdrftr2.CenterHeaderField.Set("Title: *****", New Font("Arial", 12.0F, FontStyle.Regular), Color.Black)
' set right footer field
hdrftr2.RightFooterField.Set("Page <<1/n>>", New Font("Arial", 9.0F, FontStyle.Regular), Color.DarkGray)
' define page range all even pages
Dim pageRange2 As PageRangeOptions = New PageRangeOptions()
pageRange2.AllPages = True
pageRange2.Subset = PageRangeSubset.Even
' apply header/footer settings to all even pages
PDFPageFieldHandler.ApplyHeaderFooter(doc, hdrftr2, pageRange2)
doc.Save(outputFilePath)