Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine number of pages in a PDF file [closed]

Tags:

c#

pdf

.net-2.0

I need to determine the number of pages in a specified PDF file using C# code (.NET 2.0). The PDF file will be read from the file system, and not from an URL. Does anyone have any idea on how this could be done? Note: Adobe Acrobat Reader is installed on the PC where this check will be carried out.

like image 251
Tangiest Avatar asked Nov 26 '08 10:11

Tangiest


People also ask

How can I count pages in PDF without opening?

In Adobe Acrobat Pro, go to file > create PDF > merge files into a single PDF. Then add files and select the files you want. Click combine, and see how many pages are in the final PDF.

How do you find out the number of pages in a PDF?

The R package pdftools and the function pdf_info() provides information on the number of pages in a pdf.

How can I tell when a PDF was last opened?

If you go file>open recent. A list containing your last 9 files will display and you can choose from there the one you want to open, or you can also click "history" and search files you opened today, yesterday 14 days ago, etc. Hope this helps.

How do I track opens on a PDF?

Right-click on your PDFs in Windows File Explorer and select the menu option 'Make Secure PDF' to invoke Safeguard Secure PDF Writer. In Safeguard Enterprise Secure PDF Writer, go to the Printing & Viewing tab: To track PDF opens, check the box 'log document views'


1 Answers

You'll need a PDF API for C#. iTextSharp is one possible API, though better ones might exist.

iTextSharp Example

You must install iTextSharp.dll as a reference. Download iTextsharp from SourceForge.net This is a complete working program using 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();       }    } } 
like image 82
darkdog Avatar answered Sep 21 '22 17:09

darkdog