ByteScout PDF SDK - C# - Add Page Numbers - ByteScout

ByteScout PDF SDK – C# – Add Page Numbers

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF SDK – C# – Add Page Numbers

How to add page numbers in C# using ByteScout PDF SDK

The tutorial below will demonstrate how to add page numbers in C#

With this source code sample you may quickly learn how to add page numbers in C#. What is ByteScout PDF SDK? It is the SDK for pdf documents generation, modification and updates. Can also generate and fill PDF forms. Provides support for text (fonts, style, size, font family), layers, pdf form fields, vector and raster drawings. It can help you to add page numbers in your C# application.

This code snippet below for ByteScout PDF SDK works best when you need to quickly add page numbers in your C# application. Just copy and paste the code into your C# application’s code and follow the instruction. Enjoy writing a code with ready-to-use sample codes in C#.

Free trial version of ByteScout PDF SDK is available for download from our website. Get it to try other source code samples for C#.

Try ByteScout PDF SDK today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

Program.cs
      
using Bytescout.PDF; using System; using System.Diagnostics; using Font = Bytescout.PDF.Font; using SolidBrush = Bytescout.PDF.SolidBrush; namespace AddHeaderAndFooter { class Program { #region Declarations private enum PageNoStyle { TopLeft, TopRight, BottomLeft, BottomRight } #endregion static void Main(string[] args) { try { using (Document doc = new Document()) { // Add registration keys doc.RegistrationName = "demo"; doc.RegistrationKey = "demo"; // Load document doc.Load("sample.pdf"); // Write template in each pages for (int i = 0; i < doc.Pages.Count; i++) { Page currentPage = doc.Pages[i]; _AddPageNo(currentPage, "Page #" + (i + 1), PageNoStyle.BottomRight); } // Save output file doc.Save("result.pdf"); } // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Press enter key to exit..."); Console.ReadLine(); } } /// <summary> /// Add Page No /// </summary> private static void _AddPageNo(Page currentPage, string pageNoText, PageNoStyle pageNoStyle) { float float_left = 10; float float_top = 10; switch (pageNoStyle) { case PageNoStyle.TopRight: float_left = currentPage.Width - 60; break; case PageNoStyle.BottomLeft: float_top = currentPage.Height - 20; break; case PageNoStyle.BottomRight: float_top = currentPage.Height - 20; float_left = currentPage.Width - 60; break; case PageNoStyle.TopLeft: default: break; } // Draw/Write page no currentPage.Canvas.DrawString(pageNoText, new Font(StandardFonts.CourierBold, 12), new SolidBrush(), float_left, float_top); } } }

Try ByteScout PDF SDK today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

VIDEO

ON-PREMISE VERSION INFORMATION

Get 60 Day Free Trial or Visit ByteScout PDF SDK Home Page

Explore ByteScout PDF SDK Documentation

Get ByteScout PDF SDK Free Training

WEB API

Get Your Free API Key

Explore Web API Documentation

Tutorials:

prev
next