Table of Contents

Method GetPageCount

Namespace
LMKit.Document.Pdf
Assembly
LM-Kit.NET.dll

GetPageCount(string, string)

Returns the number of pages in the PDF.

public static int GetPageCount(string inputPath, string password = "")

Parameters

inputPath string

Path to the source PDF.

password string

Password for encrypted PDFs. Empty for unprotected documents.

Returns

int

Examples

using LMKit.Document.Pdf;

int pages = PdfRenderer.GetPageCount("report.pdf");
Console.WriteLine($"Document has {pages} page(s).");

// Encrypted file
int securedPages = PdfRenderer.GetPageCount("locked.pdf", password: "s3cret!");

GetPageCount(Stream, string, bool)

Returns the number of pages in the PDF.

public static int GetPageCount(Stream input, string password = "", bool leaveOpen = true)

Parameters

input Stream

Readable stream containing the PDF.

password string

Password for encrypted PDFs.

leaveOpen bool

When true (default), the caller keeps ownership of the stream.

Returns

int

Examples

using System.IO;
using LMKit.Document.Pdf;

using FileStream fs = File.OpenRead("report.pdf");
int pages = PdfRenderer.GetPageCount(fs);
Console.WriteLine($"Stream contains {pages} page(s).");

GetPageCount(byte[], string)

Returns the number of pages in the PDF.

public static int GetPageCount(byte[] data, string password = "")

Parameters

data byte[]

PDF file content as a byte array.

password string

Password for encrypted PDFs.

Returns

int

Examples

using System.IO;
using LMKit.Document.Pdf;

byte[] bytes = File.ReadAllBytes("report.pdf");
int pages = PdfRenderer.GetPageCount(bytes);
Console.WriteLine($"In-memory PDF has {pages} page(s).");
Share