Click or drag to resize

Built-in Utilities

Built-in Utilities

ReadySuite provides two static utility classes — ScriptUtil and PdfUtil — that offer common helper methods for file operations, encoding detection, image inspection, and PDF processing.

ScriptUtil
GetResourcePath

Returns the full path to a resource file on disk, given a document and a resource reference:

C#
var native = document.GetNative();
string fullPath = ScriptUtil.GetResourcePath(document, native);
TryDetectTextFileEncoding

Detects the encoding of a text file. Returns true if the encoding was detected, with the result in the out parameter:

C#
Encoding encoding;
if (ScriptUtil.TryDetectTextFileEncoding(filePath, out encoding))
{
    // Use the detected encoding
    var text = File.ReadAllText(filePath, encoding);
}
GetImageFrameCount

Returns the number of frames in an image file. Useful for detecting multi-page TIFFs:

C#
int frameCount = ScriptUtil.GetImageFrameCount(imageFilePath);
if (frameCount > 1)
{
    script.AddMessage("Multi-frame image detected.");
}
RetrieveDelimitedFileHeaders

Reads the first row of a delimited file and returns the column headers. Requires a ScriptContainer reference for configuration:

C#
var headers = ScriptUtil.RetrieveDelimitedFileHeaders(this, filePath);
foreach (var header in headers)
{
    script.AddMessage(header);
}
PdfUtil

PdfUtil provides methods for reading PDF metadata, manipulating PDF documents, and converting between PDF formats.

Getting a PDF Document

Open a PDF from a file path or from an in-memory stream:

C#
var pdf = PdfUtil.GetPdfDocument(filePath);
var pdf = PdfUtil.GetPdfDocument(stream);

A stream overload accepts a password for encrypted files:

C#
var pdf = PdfUtil.GetPdfDocument(stream, password);
Creating a New PDF Document
C#
var pdf = PdfUtil.GetNewPdfDocument();
Reading PDF Metadata

Retrieve metadata without opening the full document:

C#
var metadata = PdfUtil.GetPdfMetadata(filePath);

Password and stream overloads are also available:

C#
var metadata = PdfUtil.GetPdfMetadata(filePath, password);
var metadata = PdfUtil.GetPdfMetadata(stream);
var metadata = PdfUtil.GetPdfMetadata(stream, password);
IPdfMetadata Properties
PropertyTypeDescription
AuthorstringDocument author
CreatorstringCreating application
KeywordsstringKeywords
ProducerstringPDF producer
SubjectstringDocument subject
TitlestringDocument title
CreatedDateDateTimeCreation date
ModifiedDateDateTimeLast modified date
PageCountintNumber of pages
IsEncryptedboolWhether the file is encrypted
IsValidPdfFileboolWhether the file is a valid PDF
HasOpenPasswordboolWhether a password is needed to open
HasEditPasswordboolWhether a password is needed to edit
HasCollectionboolWhether the PDF contains a portfolio/collection
IPdfDocument Operations

Once you have an IPdfDocument, you can inspect, convert, optimize, and extract content.

Properties
PropertyTypeDescription
IsEncryptedboolWhether the document is encrypted
IsPdfACompliantboolWhether the document is PDF/A compliant
IsPdfUaCompliantboolWhether the document is PDF/UA compliant
FormatPdfFormatThe document's PDF format
Methods
MethodDescription
GetPageCount()Returns the number of pages
GetText()Extracts text from the entire document
GetText(PdfTextFormattingMode mode)Extracts text with formatting control
GetPdfFormat()Returns the detected PDF format
GetEmbeddedFileCount()Returns the number of embedded files
Save(string path)Saves the document to a file
CopyPage(IPdfDocument source, int page)Copies a page from another document
Convert(PdfFormat format)Converts to a different PDF format
Validate(PdfFormat format)Validates against a PDF format
Optimize(IPdfOptimizationOptions options)Optimizes the document
Text Extraction

Extract text from the document:

C#
var pdf = PdfUtil.GetPdfDocument(filePath);
string text = pdf.GetText();

Control formatting with PdfTextFormattingMode:

C#
string text = pdf.GetText(PdfTextFormattingMode.Pure);
ModeDescription
RawPreserves the original text order from the PDF stream
PureAttempts to reconstruct the visual layout
FlattenReturns text with minimal formatting
PDF Optimization

Create optimization options and apply them:

C#
var options = PdfUtil.GetNewOptimizationOptions();
options.CompressImages = true;
options.ImageQuality = 75;
options.RemoveUnusedObjects = true;
options.LinkDuplicateStreams = true;

var pdf = PdfUtil.GetPdfDocument(filePath);
pdf.Optimize(options);
pdf.Save(outputPath);
IPdfOptimizationOptions
PropertyTypeDefaultDescription
RemoveUnusedObjectsboolRemove objects not referenced
RemoveUnusedStreamsboolRemove unused data streams
LinkDuplicateStreamsboolLink identical streams to save space
AllowReusePageContentboolAllow reuse of identical page content
UnembedFontsboolRemove embedded fonts
CompressObjectsboolCompress PDF objects
CompressImagesboolCompress image resources
ImageQualityintJPEG quality (1–100)
ResizeImagesboolResize images to max resolution
MaxResolutionintMaximum image resolution (DPI)
FastCompressionboolUse faster but less effective compression
PDF Format Conversion

Convert a document to a specific PDF format:

C#
var pdf = PdfUtil.GetPdfDocument(filePath);
pdf.Convert(PdfFormat.PDF_A_1B);
pdf.Save(outputPath);

The PdfFormat enum includes formats such as PDF_A_1A, PDF_A_1B, PDF_A_2A, PDF_A_2B, PDF_A_3A, PDF_A_3B, and many others.

Getting a Document's PDF Path

Resolve the path to a document's PDF representation:

C#
string pdfPath = PdfUtil.GetDocumentPdfPath(document);