Skip to content

PdfClientService

PdfClientService is the only behavior-bearing type in the library — a static, stateless iTextSharp-backed facade providing PDF inspection (IsPdf, Version, GetPageCount, HasFormFields), transformation (Flatten, ExtractPages/ExtractPageRanges), and guard (ValidatePdf) operations. It is consumed directly by PdfAPI\Services\PdfService.cs, re-exposed as instance methods by PdfAPI.Client\PdfClient.cs, and executes entirely in the caller's process with no network or database access.

Purpose

  • Provides low-level, stateless PDF inspection and transformation primitives backed by iTextSharp 5.5.11.
  • Enforces the input-validation guard used throughout the platform before any PDF byte array is trusted. (BR-01, BR-03)
  • Because all members are static, consumers cannot substitute or mock this service directly; PdfAPI\Services\PdfService.cs wraps it in instance methods to allow switching to alternative implementations.

Context

  • Namespace: PdfAPI.Core
  • Assembly/package: PdfAPI.Core

Public members

Member Signature Purpose
HasFormFields(byte[]) static bool HasFormFields(byte[] file) Detects whether the PDF contains an AcroForm with fillable form fields. (BR-10)
Flatten(byte[]) static byte[] Flatten(byte[] file) Flattens AcroForm form fields into static content, returning the original bytes unchanged when no AcroForm is present. (BR-11)
IsPdf(byte[]) static bool IsPdf(byte[] file) Tests whether the byte array begins with the %PDF- signature. (BR-01, BR-02)
Version(byte[]) static string Version(byte[] file) Reads the PDF version declared in the file header. (BR-08)
GetPageCount(byte[]) static int GetPageCount(byte[] file) Counts pages by scanning for page markers. (BR-09)
ExtractPages(DocumentRange) static PdfResult ExtractPages(DocumentRange documentRange) Opens the source document and delegates to ExtractPageRanges to produce a new PDF containing the selected pages. See Extract pages.
ExtractPageRanges(PdfReader, DocumentRange) static PdfResult ExtractPageRanges(iTextSharp.text.pdf.PdfReader sourceDocReader, DocumentRange documentRange) Copies the selected page ranges from an already-open PdfReader into a new PDF via PdfCopy. See Extract pages. (BR-12, BR-13, BR-14, BR-15, BR-16, BR-17, BR-18)
ValidatePdf(byte[], string) static void ValidatePdf(byte[] file, string fileName = null) Throws PdfException when file is not a valid PDF. See Validate PDF bytes. (BR-01, BR-02, BR-03)
ValidatePdf(Document, PdfOptions) static void ValidatePdf(Document document, PdfOptions options) Loads a document, optionally deletes its source file, and validates the resulting bytes. See Validate a document. (BR-04, BR-05, BR-06, BR-07)

Behavioral notes

  • ExtractPageRanges exposes iTextSharp.text.pdf.PdfReader in its public signature, making iTextSharp a compile-time-visible dependency for any package consumer that calls this overload directly.
  • ValidatePdf(Document, PdfOptions) deletes the on-disk source file (step 4) before running the PDF signature check (step 5), so a document that fails validation has already lost its on-disk copy. (BR-07)

Constraints and usage notes

  • All members are static; there is no instance to construct, inject, or mock. Callers needing substitutability must wrap this type themselves.

Sources

  • PdfAPI.Core\Services\PdfClientService.cs