An easy to understand sample source code to learn how to add page numbers to pdf with pdf sdk in VB.NET ByteScout PDF Suite is the bundle that provides six different SDK libraries to work with PDF from generating rich PDF reports to extracting data from PDF documents and converting them to HTML. This bundle includes PDF (Generator) SDK, PDF Renderer SDK, PDF Extractor SDK, PDF to HTML SDK, PDF Viewer SDK and PDF Generator SDK for Javascript. It can be applied to add page numbers to pdf with pdf sdk using VB.NET.
The following code snippet for ByteScout PDF Suite works best when you need to quickly add page numbers to pdf with pdf sdk in your VB.NET application. This VB.NET sample code is all you need for your app. Just copy and paste the code, add references (if needs to) and you are all set! Complete and detailed tutorials and documentation are available along with installed ByteScout PDF Suite if you’d like to learn more about the topic and the details of the API.
You can download free trial version of ByteScout PDF Suite from our website to see and try many others source code samples for VB.NET.
On-demand (REST Web API) version:
Web API (on-demand version)
On-premise offline SDK for Windows:
60 Day Free Trial (on-premise)
Imports Bytescout.PDF
Imports Font = Bytescout.PDF.Font
Imports SolidBrush = Bytescout.PDF.SolidBrush
Module Program
#Region "Declarations"
Private Enum PageNoStyle
TopLeft
TopRight
BottomLeft
BottomRight
End Enum
#End Region
Sub Main()
Try
Using doc As Document = New Document()
' Add registration keys
doc.RegistrationName = "demo"
doc.RegistrationKey = "demo"
' Load document
doc.Load("sample.pdf")
' Write template in each pages
For i As Integer = 0 To doc.Pages.Count - 1
Dim currentPage As Page = doc.Pages(i)
_AddPageNo(currentPage, "Page #" & (i + 1), PageNoStyle.BottomRight)
Next
' Save output file
doc.Save("result.pdf")
End Using
' Open output file
Process.Start("result.pdf")
Catch ex As Exception
Console.WriteLine(ex.Message)
Console.WriteLine("Press enter key to exit...")
Console.ReadLine()
End Try
End Sub
''' <summary>
''' Add Page No
''' </summary>
Private Sub _AddPageNo(ByVal currentPage As Page, ByVal pageNoText As String, ByVal pageNoStyle As PageNoStyle)
Dim float_left As Single = 10
Dim float_top As Single = 10
Select Case pageNoStyle
Case PageNoStyle.TopRight
float_left = currentPage.Width - 60
Case PageNoStyle.BottomLeft
float_top = currentPage.Height - 20
Case PageNoStyle.BottomRight
float_top = currentPage.Height - 20
float_left = currentPage.Width - 60
Case Else
End Select
' Draw/Write page no
currentPage.Canvas.DrawString(
pageNoText,
New Font(StandardFonts.CourierBold, 12),
New SolidBrush(),
float_left,
float_top)
End Sub
End Module
60 Day Free Trial or Visit ByteScout PDF Suite Home Page
Explore ByteScout PDF Suite Documentation
Explore Samples
Sign Up for ByteScout PDF Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
60 Day Free Trial or Visit ByteScout PDF Suite Home Page
Explore ByteScout PDF Suite Documentation
Explore Samples
Sign Up for ByteScout PDF Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
also available as: