ByteScout PDF Suite - C# - Add page numbers with pdf sdk - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout PDF Suite – C# – Add page numbers with pdf sdk

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Suite – C# – Add page numbers with pdf sdk

How to add page numbers with pdf sdk in C# with ByteScout PDF Suite

This code in C# shows how to add page numbers with pdf sdk with this how to tutorial

Every ByteScout tool includes simple example C# source codes that you can get here or in the folder with installed ByteScout product. Want to add page numbers with pdf sdk in your C# app? ByteScout PDF Suite is designed for it. ByteScout PDF Suite is the set that includes 6 SDK products 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.

Want to save time? You will save a lot of time on writing and testing code as you may just take the C# code from ByteScout PDF Suite for add page numbers with pdf sdk below and use it in your application. IF you want to implement the functionality, just copy and paste this code for C# below into your code editor with your app, compile and run your application. Applying C# application mostly includes various stages of the software development so even if the functionality works please test it with your data and the production environment.

ByteScout provides the free trial version of ByteScout PDF Suite along with the documentation and source code samples.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

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); } } }

ON-PREMISE OFFLINE SDK

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

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

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

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next