IRONPDF 사용 How to Add Page Numbers in PDF using C# 커티스 차우 업데이트됨:6월 22, 2025 다운로드 IronPDF NuGet 다운로드 DLL 다운로드 윈도우 설치 프로그램 무료 체험 시작하기 LLM용 사본 LLM용 사본 LLM용 마크다운 형식으로 페이지를 복사하세요 ChatGPT에서 열기 ChatGPT에 이 페이지에 대해 문의하세요 제미니에서 열기 제미니에게 이 페이지에 대해 문의하세요 Grok에서 열기 Grok에게 이 페이지에 대해 문의하세요 혼란 속에서 열기 Perplexity에게 이 페이지에 대해 문의하세요 공유하다 페이스북에 공유하기 트위터에 공유하기 LinkedIn에 공유하기 URL 복사 이메일로 기사 보내기 "Portable Document Format," or PDF, is a file format created by Adobe. PDFs come in handy when presenting papers that need to have their text and photos formatted. In the current world, PDF files are essential and are utilized for document creation and invoicing across all corporate sectors. Thanks to the several PDF libraries that are now on the market, creating PDFs has become practically instinctive. To choose the appropriate PDF library for you, it is crucial to weigh the benefits and characteristics of each before utilizing one for your project. In this article, we are going to see how to add page numbers in PDF using iTextSharp C#. Also, we will compare iTextSharp with IronPDF. How to Add Page Numbers in PDF using iTextSharp C# Create a new C# project using any IDE. Create a new PDF object. Add page numbers to the HTML footer. Create a PDF from HTML material. Save a PDF file to your computer. What is IronPDF IronPDF is a robust PDF .NET Framework that developers use to produce, view, and edit PDFs with ease. IronPDF is a sophisticated tool that runs on a chromium engine internally. It can convert HTML5, JavaScript, CSS, and picture files to PDF, add custom Headers and Footers, and produce PDFs precisely as they appear in a browser. Many online and net formats, including HTML, ASPX, Razor View, and MVC, are supported by IronPDF. IronPDF Features Utilizing .NET C# code to create, read, and simply edit PDF files. The process of creating PDFs from a website URL link while managing User-Agents, Proxies, Cookies, HTTP headers, and form variables to enable login using HTML login forms. Removing images from already existing PDF files. Including elements of a PDF: table, text, photos, bookmarks, watermarks, headers, footers, and others. The ability to separate and combine pages of numerous PDF documents with ease. To know more about the IronPDF documentation, refer here. Installing IronPDF Within the Visual Studio Tools, select the NuGet Package Manager, and you can find the Visual Command-Line interface under Tools. The command below should be entered into the package management terminal tab. Install-Package IronPdf Or we can use the Package manager method. Installing the package straight into the solution is possible with Visual Studio's NuGet Package Manager option. A search box is available for locating packages on the NuGet website. We only need to look for "IronPDF" in the package manager, as the screenshot below illustrates: The list of relevant search results is displayed above. For the package to be installed on your system, please make the necessary selections. Now that the package has been downloaded and installed, it may be utilized in the current project. What is iTextSharp iTextSharp is a flexible library for producing and modifying PDF documents in C#. It offers several features, such as encryption, PDF merging, text and picture extraction, and much more. iTextSharp is an efficient tool for numerous tasks, including adding page numbers to PDFs. iTextSharp features An API to generate PDF documents is available through the iText library. Both HTML and XML strings may be parsed into PDF files using the iText program. We may add bookmarks, page numbers, and markers to our PDF documents by using the iText library. We can also split a PDF document into numerous PDFs or merge multiple PDF documents into a single PDF by using the iText library. We can modify PDF forms with iText. Install iTextSharp Use the NuGet package manager to look for iText. iText7 and iText.pdfhtml are required installations since iText functionalities are divided across many packages. Should you choose the Visual Command-Line interface, the following packages need to be installed: Install-Package iTextSharp Since iText 7 is the most recent version, it is the one we are employing in our solution. Adding Page Numbers using IronPDF Adding page numbers to PDF files is made simple through IronPDF's comprehensive library. To illustrate, see the below code. using IronPdf; class Program { static void Main(string[] args) { // Create a new HtmlToPdf renderer instance var renderer = new HtmlToPdf(); // Define the HTML content with a header string header = "<h1>Hello IronPDF!</h1>"; // Render the HTML as a PDF document PdfDocument pdf = renderer.RenderHtmlAsPdf(header); // Define the HTML footer with page numbers HtmlHeaderFooter htmlFooter = new HtmlHeaderFooter() { HtmlFragment = "<center><i>{page} of {total-pages}</i></center>" }; // Add footer to the PDF pdf.AddHtmlFooters(htmlFooter); // Save the PDF document to a file pdf.SaveAs("output.pdf"); } } using IronPdf; class Program { static void Main(string[] args) { // Create a new HtmlToPdf renderer instance var renderer = new HtmlToPdf(); // Define the HTML content with a header string header = "<h1>Hello IronPDF!</h1>"; // Render the HTML as a PDF document PdfDocument pdf = renderer.RenderHtmlAsPdf(header); // Define the HTML footer with page numbers HtmlHeaderFooter htmlFooter = new HtmlHeaderFooter() { HtmlFragment = "<center><i>{page} of {total-pages}</i></center>" }; // Add footer to the PDF pdf.AddHtmlFooters(htmlFooter); // Save the PDF document to a file pdf.SaveAs("output.pdf"); } } $vbLabelText $csharpLabel First, we define the HTML text that has to be turned into a PDF. This HTML content may consist of a single HTML paragraph or an entire HTML page. Next, we make an instance of the HtmlToPdf class, which offers the HTML-to-PDF conversion function RenderHtmlAsPdf. The HTML content is passed as an argument to the RenderHtmlAsPdf function. We specify the HTML material that has to be turned into a PDF. Page numbers are represented as placeholders, or the {page} of {total-pages} in the footer portion of this HTML text. The created PDF document is returned by this method as a PdfDocument object. Using the SaveAs method, we save the PDF document to a file with the name "output.pdf". Alternatively, we can use the OpenInDefaultPDFViewer function to open the created PDF document with the system's default PDF reader. We can also use the above method to add page numbers to an existing PDF file. To learn more about the IronPDF code, refer here. Adding Page Numbers using iTextSharp First, let's use iTextSharp to generate a new PDF document. Here's a basic illustration of how to make a new PDF document with a page number: using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { // Create a new PDF document Document doc = new Document(); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("output.pdf", FileMode.Create)); // Open the document to add content doc.Open(); doc.Add(new Paragraph("Hello, world!")); // Attach page number event to PDF writer writer.PageEvent = new PageNumberEventHandler(); // Close the document doc.Close(); } } public class PageNumberEventHandler : PdfPageEventHelper { public override void OnOpenDocument(PdfWriter writer, Document document) { base.OnOpenDocument(writer, document); } public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); // Create a table to hold the page number PdfPTable table = new PdfPTable(1); table.TotalWidth = 300f; table.HorizontalAlignment = Element.ALIGN_CENTER; PdfPCell cell = new PdfPCell(new Phrase($"Page {writer.PageNumber}")); cell.Border = 0; table.AddCell(cell); // Write the table at the bottom of the page table.WriteSelectedRows(0, -1, 150f, document.Bottom, writer.DirectContent); } public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); } } } using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { // Create a new PDF document Document doc = new Document(); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("output.pdf", FileMode.Create)); // Open the document to add content doc.Open(); doc.Add(new Paragraph("Hello, world!")); // Attach page number event to PDF writer writer.PageEvent = new PageNumberEventHandler(); // Close the document doc.Close(); } } public class PageNumberEventHandler : PdfPageEventHelper { public override void OnOpenDocument(PdfWriter writer, Document document) { base.OnOpenDocument(writer, document); } public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); // Create a table to hold the page number PdfPTable table = new PdfPTable(1); table.TotalWidth = 300f; table.HorizontalAlignment = Element.ALIGN_CENTER; PdfPCell cell = new PdfPCell(new Phrase($"Page {writer.PageNumber}")); cell.Border = 0; table.AddCell(cell); // Write the table at the bottom of the page table.WriteSelectedRows(0, -1, 150f, document.Bottom, writer.DirectContent); } public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); } } } $vbLabelText $csharpLabel First, we create a new object for Document and PdfWriter, which allows us to create an empty PDF file. You may include text, photos, tables, and other types of material in your PDF document. Let's use a Paragraph to add some sample text for demonstration purposes. The important step is now to add page numbers to the PDF document. We'll use iTextSharp's page events for this. We start by defining a class that inherits from the PdfPageEventHelper class to be able to override methods that are called when specific events happen during the PDF-generating process. The OnEndPage function is overridden in this class to add a table that has a single cell containing the current page number. Lastly, before we close the document, we need to connect an instance of our PageNumberEventHandler class to the PdfWriter object. With this configuration, the PageNumberEventHandler class's OnEndPage function will be called each time a new page is added to the PDF document, adding the page number at the bottom of each page. We can also use an existing PDF document to add page numbers. Conclusion In summary, IronPDF's specialization, usability, and seamless integration with .NET environments position it as the best option for scenarios requiring HTML to PDF conversion and related functionalities, even though iTextSharp is still a strong competitor in the landscape of C# PDF manipulation libraries. With IronPDF, you can create invoices, reports, and dynamically produced documents from HTML content with the ease, effectiveness, and adaptability required to succeed in the modern development environment. A permanent license, upgrade options, and a year of software maintenance are all included in IronPDF's Lite edition. The watermarked trial period allows users to assess the product in practical settings. Visit the license page for more details. Go to this website to learn more about Iron Software. 자주 묻는 질문 C#을 사용하여 PDF에 페이지 번호를 추가하려면 어떻게 해야 하나요? IronPDF를 사용하여 페이지 번호 플레이스홀더로 HTML 콘텐츠를 정의하고 AddHtmlFooters 메서드를 사용하여 PDF의 바닥글로 적용하여 PDF에 페이지 번호를 추가할 수 있습니다. PDF 조작에 IronPDF를 사용하면 어떤 이점이 있나요? IronPDF는 HTML5, JavaScript, CSS 및 이미지에서 PDF로의 변환을 지원하는 강력한 PDF.NET 프레임워크 기능을 제공하여 사용자 정의 머리글과 바닥글을 사용하여 PDF를 쉽게 조작할 수 있습니다. 페이지 번호를 추가하는 데 있어 iTextSharp와 IronPDF를 어떻게 비교하나요? iTextSharp는 PdfPageEventHelper 클래스를 사용하여 페이지 번호를 처리하는 반면, IronPDF는 페이지 번호 자리 표시자를 사용하여 HTML 바닥글을 정의할 수 있도록 하여 더 간단한 접근 방식을 제공합니다. 기존 PDF 파일을 조작하여 페이지 번호를 추가할 수 있나요? 예, IronPDF를 사용하면 페이지 번호 자리 표시자가 있는 HTML 바닥글을 렌더링하고 원본 문서와 병합하여 기존 PDF 파일에 페이지 번호를 추가할 수 있습니다. HTML을 PDF로 변환할 때 선호하는 방법은 무엇인가요? IronPDF는 .NET 환경과의 원활한 통합과 HTML5, JavaScript 및 CSS를 처리할 수 있는 기능으로 인해 HTML을 PDF로 변환하는 데 선호됩니다. C# 프로젝트에서 IronPDF를 사용하기 위한 설치 단계는 무엇인가요? Visual Studio의 NuGet 패키지 관리자를 사용하여 C# 프로젝트에서 'IronPDF'를 검색하고 프로젝트에 추가하여 IronPDF를 설치할 수 있습니다. C#을 사용하여 PDF의 정확한 페이지 번호를 확보하려면 어떻게 해야 하나요? IronPDF를 사용하여 페이지 번호 자리 표시자가 있는 HTML 템플릿을 정의하고 모든 PDF 페이지에 일관되게 적용하여 페이지 번호가 정확한지 확인하세요. IronPDF에 사용할 수 있는 라이선스 옵션이 있나요? IronPDF는 영구 라이선스, 업그레이드 옵션, 1년간의 소프트웨어 유지보수가 포함된 '라이트' 에디션과 평가를 위한 워터마크가 표시된 평가판 기간을 제공합니다. IronPDF 사용에 대한 자세한 예제와 문서는 어디에서 찾을 수 있나요? IronPDF 사용에 대한 종합적인 문서와 예제는 공식 웹사이트(ironpdf.com)에서 확인할 수 있습니다. IronPDF는 .NET 10과 완벽하게 호환되며 .NET 10 프로젝트에서 페이지 번호 매기기 기능을 사용할 수 있나요? 예, IronPDF는 .NET 10을 지원하며 머리글 또는 바닥글의 자리 표시자를 통한 페이지 번호 매기기를 포함한 모든 기능이 특별한 구성이나 해결 방법 없이 .NET 10 프로젝트에서 즉시 작동합니다. 커티스 차우 지금 바로 엔지니어링 팀과 채팅하세요 기술 문서 작성자 커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다. 커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다. 관련 기사 업데이트됨 1월 22, 2026 How to Create PDF Documents in .NET with IronPDF: Complete Guide Discover effective methods to create PDF files in C# for developers. Enhance your coding skills and streamline your projects. Read the article now! 더 읽어보기 업데이트됨 1월 21, 2026 How to Merge PDF Files in VB.NET: Complete Tutorial Merge PDF VB NET with IronPDF. Learn to combine multiple PDF files into one document using simple VB.NET code. Step-by-step examples included. 더 읽어보기 업데이트됨 1월 21, 2026 C# PDFWriter Tutorial: Create PDF Documents in .NET Learn to create PDFs efficiently using C# PDFWriter with this step-by-step guide for developers. Read the article to enhance your skills today! 더 읽어보기 How to Extract Data from PDF in C#C# Add Image to PDF (Developer Tutorial)
업데이트됨 1월 22, 2026 How to Create PDF Documents in .NET with IronPDF: Complete Guide Discover effective methods to create PDF files in C# for developers. Enhance your coding skills and streamline your projects. Read the article now! 더 읽어보기
업데이트됨 1월 21, 2026 How to Merge PDF Files in VB.NET: Complete Tutorial Merge PDF VB NET with IronPDF. Learn to combine multiple PDF files into one document using simple VB.NET code. Step-by-step examples included. 더 읽어보기
업데이트됨 1월 21, 2026 C# PDFWriter Tutorial: Create PDF Documents in .NET Learn to create PDFs efficiently using C# PDFWriter with this step-by-step guide for developers. Read the article to enhance your skills today! 더 읽어보기