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.
Returns the full path to a resource file on disk, given a document and a resource reference:
var native = document.GetNative(); string fullPath = ScriptUtil.GetResourcePath(document, native);
Detects the encoding of a text file. Returns true if the encoding was detected, with the result in the out parameter:
Encoding encoding; if (ScriptUtil.TryDetectTextFileEncoding(filePath, out encoding)) { // Use the detected encoding var text = File.ReadAllText(filePath, encoding); }
Returns the number of frames in an image file. Useful for detecting multi-page TIFFs:
int frameCount = ScriptUtil.GetImageFrameCount(imageFilePath); if (frameCount > 1) { script.AddMessage("Multi-frame image detected."); }
Reads the first row of a delimited file and returns the column headers. Requires a ScriptContainer reference for configuration:
var headers = ScriptUtil.RetrieveDelimitedFileHeaders(this, filePath); foreach (var header in headers) { script.AddMessage(header); }
PdfUtil provides methods for reading PDF metadata, manipulating PDF documents, and converting between PDF formats.
Open a PDF from a file path or from an in-memory stream:
var pdf = PdfUtil.GetPdfDocument(filePath); var pdf = PdfUtil.GetPdfDocument(stream);
A stream overload accepts a password for encrypted files:
var pdf = PdfUtil.GetPdfDocument(stream, password);var pdf = PdfUtil.GetNewPdfDocument();Retrieve metadata without opening the full document:
var metadata = PdfUtil.GetPdfMetadata(filePath);Password and stream overloads are also available:
var metadata = PdfUtil.GetPdfMetadata(filePath, password); var metadata = PdfUtil.GetPdfMetadata(stream); var metadata = PdfUtil.GetPdfMetadata(stream, password);
| Property | Type | Description |
|---|---|---|
| Author | string | Document author |
| Creator | string | Creating application |
| Keywords | string | Keywords |
| Producer | string | PDF producer |
| Subject | string | Document subject |
| Title | string | Document title |
| CreatedDate | DateTime | Creation date |
| ModifiedDate | DateTime | Last modified date |
| PageCount | int | Number of pages |
| IsEncrypted | bool | Whether the file is encrypted |
| IsValidPdfFile | bool | Whether the file is a valid PDF |
| HasOpenPassword | bool | Whether a password is needed to open |
| HasEditPassword | bool | Whether a password is needed to edit |
| HasCollection | bool | Whether the PDF contains a portfolio/collection |
Once you have an IPdfDocument, you can inspect, convert, optimize, and extract content.
| Property | Type | Description |
|---|---|---|
| IsEncrypted | bool | Whether the document is encrypted |
| IsPdfACompliant | bool | Whether the document is PDF/A compliant |
| IsPdfUaCompliant | bool | Whether the document is PDF/UA compliant |
| Format | PdfFormat | The document's PDF format |
| Method | Description |
|---|---|
| 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 |
Extract text from the document:
var pdf = PdfUtil.GetPdfDocument(filePath); string text = pdf.GetText();
Control formatting with PdfTextFormattingMode:
string text = pdf.GetText(PdfTextFormattingMode.Pure);| Mode | Description |
|---|---|
| Raw | Preserves the original text order from the PDF stream |
| Pure | Attempts to reconstruct the visual layout |
| Flatten | Returns text with minimal formatting |
Create optimization options and apply them:
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);
| Property | Type | Default | Description |
|---|---|---|---|
| RemoveUnusedObjects | bool | — | Remove objects not referenced |
| RemoveUnusedStreams | bool | — | Remove unused data streams |
| LinkDuplicateStreams | bool | — | Link identical streams to save space |
| AllowReusePageContent | bool | — | Allow reuse of identical page content |
| UnembedFonts | bool | — | Remove embedded fonts |
| CompressObjects | bool | — | Compress PDF objects |
| CompressImages | bool | — | Compress image resources |
| ImageQuality | int | — | JPEG quality (1–100) |
| ResizeImages | bool | — | Resize images to max resolution |
| MaxResolution | int | — | Maximum image resolution (DPI) |
| FastCompression | bool | — | Use faster but less effective compression |
Convert a document to a specific PDF format:
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.
Resolve the path to a document's PDF representation:
string pdfPath = PdfUtil.GetDocumentPdfPath(document);