ByteScout Premium Suite - C# - Add page numbers with pdf sdk - ByteScout

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

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

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

Learn to code in C# to add page numbers with pdf sdk with this step-by-step tutorial

Quickly learn how to add page numbers with pdf sdk in C# with this sample source code. Want to add page numbers with pdf sdk in your C# app? ByteScout Premium Suite is designed for it. ByteScout Premium Suite is the set that includes 12 SDK products from ByteScout including tools and components for PDF, barcodes, spreadsheets, screen video recording.

This prolific sample source code in C# for ByteScout Premium Suite contains various functions and other necessary options you should do calling the API to add page numbers with pdf sdk. 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.

You can download free trial version of ByteScout Premium Suite from our website with this and other source code samples for C#.

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 Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium 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 Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next