C # – Determine the number of pages in the PDF file

I need to use C# code (.NET 2.0) to determine the number of pages in a specified PDF file. The PDF file will be read from the file system, not from the URL. Does anyone Any pointers on how to do this? Note: Adobe Acrobat Reader will be installed on the PC performing this check.
You need a C# PDF API. iTextSharp It is a possible API, but there may be a better API.

iTextSharp example

You must install iTextSharp.dll as a reference. Download iTextsharp from SourceForge.net It is a complete working program that uses a console application.

using System;
using System.Collections.Generic;
using System.Linq;< br />using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text.xml;
namespace GetPages_PDF
{
class Program
{
static void Main(string[] args)
{
// Right side of equation is location of YOUR pdf file
string ppath = "C:\\aworking\ \Hawkins.pdf";
PdfReader pdfReader = new PdfReader(ppath);
int numberOfPages = pdfReader.NumberOfPages;
Console.WriteLine(numberOfPages);
Console.ReadLine() ;
}
}
)

I need to use C# code (.NET 2.0) to determine the number of pages in a specified PDF file. The PDF file will be read from the file system, not from the URL. Does anyone have any ideas on how to do this Any instructions? Note: Adobe Acrobat Reader will be installed on the PC performing this check.

You need a C# PDF API. iTextSharp is a possible API, but there may be better API.

iTextSharp example

You must install iTextSharp.dll as a reference. Download iTextsharp from SourceForge.net This is a complete working program that uses a console application.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text.xml;
namespace GetPages_PDF
{
class Program
{
static void Main(string[ ] args)
{
// Right side of equation is location of YOUR pdf file
string ppath = "C:\\aworking\\Hawkins.pdf";
PdfReader pdfReader = new PdfReader(ppath);
int numberOfPages = pdfReader.NumberOfPages;
Console.WriteLine(numberOfPages);
Console.ReadLine();
}
}< br />}

Leave a Comment

Your email address will not be published.