Click or drag to resize

Working with Resources

Working with Resources

Documents in ReadySuite can have three types of resources: natives (the original file), pages (images produced during processing), and text (extracted or OCR text). All three share a common base — ResourceFileItem — which provides path and file-extension properties.

ResourceFileItem (Common Properties)

Every resource type exposes these properties:

PropertyDescription
FileFolderFolder path relative to the root
FileNameFile name including extension
FileExtensionExtension (e.g. .pdf, .tif)
FilePathRelative path (folder + file name)
RootPathAbsolute root path on disk
GetFullPath()Returns the full absolute path to the file
Natives

A NativeItem is the original source file for a document (e.g. a Word document, PDF, or email).

Checking and Reading
C#
if (document.HasNative())
{
    var native = document.GetNative();
    var fullPath = native.GetFullPath();
    var extension = native.FileExtension;
}
Replacing a Native

Create a new native reference and assign it:

C#
var newNative = document.GetNewNative(newFilePath);
document.SetNative(newNative);
script.UpdateDocument(document);
Removing a Native
C#
document.RemoveNative();
script.UpdateDocument(document);
Pages

Pages are image files (typically TIFF or JPEG) associated with a document. Each PageItem carries metadata about dimensions, resolution, and color.

Checking and Reading
C#
if (document.HasPages())
{
    var pages = document.GetPages();
    int count = document.GetPageCount();

    foreach (var page in pages)
    {
        var path = page.GetFullPath();
        int width = page.Width;
        int height = page.Height;
    }
}
Page Properties
PropertyTypeDescription
IdentifierstringPage identifier (e.g. bates number)
PrefixstringIdentifier prefix
PaddingintZero-padding length
CounterlongNumeric counter value
WidthintImage width in pixels
HeightintImage height in pixels
ResolutionXintHorizontal DPI
ResolutionYintVertical DPI
BitDepthintColor depth
HasColorbool?Whether the image contains color
IsBlankbool?Whether the page is blank
PixelFormatstringPixel format description
TiffCompressionstringTIFF compression type
Adding Pages
C#
var page = document.GetNewPage("IMG-0001", pageFilePath);
document.AddPage(page);
script.UpdateDocument(document);
Removing Pages

Remove a specific page or clear all pages:

C#
document.RemovePage(page);
script.UpdateDocument(document);
C#
document.ClearPages();
script.UpdateDocument(document);
Reassigning Page Numbers

After adding or removing pages, call ReassignPageNumbers() to renumber them sequentially:

C#
document.ReassignPageNumbers();
script.UpdateDocument(document);
Multi-Frame Detection

Use IsMultiFrame() to check whether a document's native file contains multiple image frames (e.g. a multi-page TIFF):

C#
if (document.IsMultiFrame())
{
    // Native contains multiple image frames
}
First and Last Page
C#
var first = document.GetFirstPage();
var last = document.GetLastPage();

These are useful for reading bates ranges — BatesBeg and BatesEnd on DocumentItem are derived from the first and last page identifiers.

Text

TextItem resources hold extracted or OCR text for a document. A document can have multiple text files.

Checking and Reading
C#
if (document.HasText())
{
    int count = document.GetTextCount();
    var textItems = document.GetText();  // Returns List<TextItem>

    foreach (var text in textItems)
    {
        var path = text.GetFullPath();
    }
}
Adding Text
C#
var textItem = document.GetNewText(textFilePath);
document.AddText(textItem);
script.UpdateDocument(document);
Replacing Text

SetText() replaces all existing text with a single text resource:

C#
var textItem = document.GetNewText(newTextFilePath);
document.SetText(textItem);
script.UpdateDocument(document);
Removing Text

Remove a specific text resource or clear all text:

C#
document.RemoveText(textItem);
script.UpdateDocument(document);
C#
document.ClearText();
script.UpdateDocument(document);
Full Example

This example reads each document's native, checks its extension, and logs the page count:

C#
public override void Run(IScriptContext script)
{
    base.Run(script);

    while (script.ReadDocument())
    {
        var document = script.Document;

        if (document.HasNative())
        {
            var native = document.GetNative();
            script.AddMessage(string.Format("{0}: {1}", document.DocId, native.FileExtension));
        }

        if (document.HasPages())
        {
            document.SetFieldData(options.PageCountField,
                document.GetPageCount().ToString());
            script.UpdateDocument(document);
        }
    }
}