My Scripts API
My Scripts API

PDFE Object

Provides access to the root object for the My Scripts Host object model.

Remarks

The pdfe object is the root object of the My Scripts Host object model hierarchy. It never needs to be instantiated before invoking its properties and methods, and it is always available from any script. The pdfe object provides access to information such as: the list of selected files passed when the script started, the name of the running script and the list of defined metadata properties. The pdfe object allows you to: access the internal specific PDF processing objects, create objects, connect to objects, sync events, stop a script's execution programmatically and output information to the output window.

This object implements also many of the Windows Script Host WScript root object methods and properties, and to make the My Scripts Host compatible with scripts for the WSH, this pdfe root object also exists under the WScript name, so WSH compatible scripts can run without changes.

Example

The following JScript code echoes the title metadata property of all the selected files used to start the script.

for (i = 0; i < pdfe.SelectedFiles.Count; i++) {
 var Item = pdfe.SelectedFiles(i);
 pdfe.echo(Item.Metadata.Title);
 }

Properties

Methods

Properties description

Arguments : IArguments (read)

(WSH) - Returns the IArguments object (a collection of arguments).

Clipboard : IClipboard (read)

Object to access the system clipboard

FullName : String (read)

(WSH) - Returns the fully qualified path of the host executable.

Host : Object (read)

Not used

Interactive : Boolean (read;write)

(WSH) - Sets or identifies the script user interaction mode. When on (the default), provides user interaction. In the off state, runs without user input/output functionality.

MetadataFieldsInfo : IMetadataFieldsInfo (read)

Returns the IMetadataFieldsInfo object (a collection of IMetadataFieldInfo objects).

OpenDialog : Object (read)

Provides a simple open file dialog object.

ProgressBar : IProgressBar (read)

Returns the IProgressBar object (an object to interface the My Scripts Host GUI main progress bar).

SaveDialog : Object (read)

Provides a simple save file dialog object.

ScriptFullName : String (read)

(WSH) - Returns the full path of the currently running script.

ScriptName : String (read)

(WSH) - Returns the currently running script name.

SelectedFiles : ISelectedFiles (read)

Returns the ISelectedFiles object (a collection of IFileObject).

Version : String (read)

(WSH) - Returns the version of the My Scripts Host.

Methods description

Alert( String msg )

Displays an alert box with a specified message and an OK button.

Parameters

BringWindowToFront( unsigned short hWnd, [Boolean KeepAlwaysOnTop] )

Brings the specified window to the top of the Z order.

Parameters

ConnectObject( Object objEventSource, String Prefix ) : Object

(WSH) - Connects the object's event sources to functions with a given prefix.

Parameters

CreateDocumentMerger( ) : IDocumentMerger

Returns a IDocumentMerger object, used to merge several documents together in a new document.

CreateFileObject( String Filename ) : IFileObject

Creates a stand alone IFileObject

Parameters

CreateObject( String ProgID, [String Prefix] ) : Object

(WSH) - Creates a COM object.

Parameters

  • ProgID : String

    String value indicating the programmatic identifier (ProgID) of the object you want to create.

  • Prefix : String (optional)

    String value indicating the function prefix.

Example

The following JScript code creates an Internet Explorer object instance, and set the event functions prefix to "objIE_". It then navigates it doing a Google search for the first selected file author metadata property. It also shows how to use the event function prefix to catch events from the object.

var objIE = pdfe.CreateObject("InternetExplorer.Application", "objIE_");
objIE.Visible = true;
objIE.Navigate('www.google.com/search?q=' + pdfe.SelectedFiles(0).Metadata.Author.replace(/\s+/g, '+'));
pdfe.BringWindowToFront(objIE.HWND);
boolBrowserRunning = true;
while (boolBrowserRunning && objIE.Visible) {
    pdfe.Sleep(500);
}

function objIE_NavigateComplete2(pDisp, URL) {
    pdfe.Echo("You just navigated to :" + URL);
}

function objIE_OnQuit() {
    boolBrowserRunning = false;
    pdfe.Echo("Closed");
}

DialogBox( String params ) : String

 

Parameters

Echo( String msg, [Integer color], [unsigned short option] )

(WSH) - Outputs text to the output window.

Parameters

  • msg : String

    String value indicating the text to output.

  • color : Integer (optional)

    Integer value indicating the RGB color of the outputted text..

  • option : unsigned short (optional)

    One of the following values:

    none=0 - Normal echo, without special treatment (default)
    append=1 - To append to the last echo output line
    replace=2 - To replace the previous echo output line
    clsscr=3 - To clear all the previous output lines. The passed msg is ignored

Example

pdfe.echo('Red',0xFF0000);
pdfe.echo('Green',0x00FF00);
pdfe.echo('Blue',0x0000FF);
pdfe.echo('Default text color');
pdfe.echo('Append to the last line',0,1);

MessageBox( String lpText, String lpCaption, unsigned short uType ) : Integer

Displays a modal dialog box that contains a system icon, a set of buttons, and a brief application-specific message, such as status or error information. The message box returns an integer value that indicates which button the user clicked.

Parameters

  • lpText : String

    The message to be displayed. If the string consists of more than one line, you can separate the lines using a carriage return and/or linefeed character between each line.

  • lpCaption : String

    The dialog box title.

  • uType : unsigned short

    The contents and behavior of the dialog box. This parameter can be a combination of flags.

Quit( [Integer ErrorCode] )

(WSH) - Forces script execution to stop at any time.

Parameters

  • ErrorCode : Integer (optional)(not used)

     

Sleep( Integer Duration )

(WSH) - Suspends script execution for a specified length of time, then continues execution.

Parameters

  • Duration : Integer

    Integer value indicating the interval (in milliseconds) you want the script process to be inactive.

VarToStr( Variant Value, [String default] ) : String

Converts a Variant to type String

Parameters

ISelectedFiles Object

The collection of the selected files objects, filtered by the file types the script can handle and in the order in which they were originally entered.

Remarks

 

Example

 

Properties

Methods

This object has no methods

Properties description

Count : Integer (read)

Returns the number of ISelectedFile items in the collection

Item( Integer Index ) : IFileObject (read;default)

Exposes a specified IFileObject item from the collection.

IFileObject Object

The root object to access all document processing functionalities.

Remarks

 

Example

 

Properties

Methods

Properties description

Annotations( [Integer Page], [String Types] ) : IAnnotations (read)

Returns the list of all the document, or document page, PDF annotations.

Parameters

  • Page : Integer (optional)

    If specified, returns only the list of annotation of this referred page index.

  • Types : String (optional)

    - A comma separated list of all the annotations types to search for. E.g. Annotations(-1, "Text,FreeText");
    - The list can contain any of the this annotation types: Text, FreeText, Line, Square, Circle, Polygon, PolyLine, Highlight, Underline, Squiggly, StrikeOut, Stamp, Caret, Ink, FileAttachment, Sound, Link, Popup, Movie, Widget, Screen, PrinterMark, TrapNet, Watermark, 3D.
    - Returns all the annotations found, if not specified or empty.

 

AttachmentRoot : IAttachment (read)

The attachments root folder for the attachments tree. This attachment does not physically exists as a real attachment but is a programmatic construct used to access the attachments tree..

BookmarkRoot : IBookmark (read)

The root bookmark for the bookmark tree. This bookmark is not displayed to the user but is a
programmatic construct used to access the tree and the child bookmarks.

DateLastModified : Date (read)

Returns the file last modification date

EmbeddedFiles : IAttachments (read)

The list of all the other embedded files, not included in the list of attachments

FileSize : Integer (read)

Returns the file size

Filename : String (read)

Returns the full path filename

Locked : Boolean (read;write)

Not used.

Metadata : IFileMetadata (read;default)

Returns the document IFileMetadata object

NumPages : Integer (read)

Returns the number of pages in the document

Pages : IPDFPages (read)

Returns the document IPDFPage object

Methods description

Close( )

Closes the PDF file handle

IPDFPages Object

The entire collection of pages of the document.

Remarks

 

Example

 

Properties

Methods

Properties description

Count : Integer (read)

Returns the number of IPDFPage items in the collection

Item( Integer Index ) : IPDFPage (read;default)

Exposes a specified IPDFPage item from the collection.

Methods description

CommitChanges( [String Filename], [Boolean CreateBackup] ) : Boolean

Save changes to the file.

Parameters

  • Filename : String (optional)

     

  • CreateBackup : Boolean (optional)

     

Example

...
Page.CropBox.left=Page.CropBox.left+10;
Page.CropBox.left=Page.CropBox.right-10;
Pages.CommitChanges();

IPDFPage Object

Represents a page object in the document.

Remarks

 

Example

 

Properties

Methods

Properties description

ArtBox : IFloatRect (read;write)

Sets or returns the page ArtBox rectangle

BleedBox : IFloatRect (read;write)

Sets or returns the page BleedBox rectangle

CropBox : IFloatRect (read;write)

Sets or returns the page CropBox rectangle

Height : Single (read)

Gets the page height

MediaBox : IFloatRect (read;write)

Sets or returns the page MediaBox rectangle

Rotation : Integer (read;write)

Sets or returns the page rotation angle

Text : String (read)

Gets the page text content.

TextEx : Object (read)

Gets the page extended text object.

TrimBox : IFloatRect (read;write)

Sets or returns the page TrimBox rectangle

Width : Single (read)

Gets the page width

Methods description

RenderToFile( String Filename, Integer DPIs, [unsigned short BKColor], [unsigned short Flags] ) : Boolean

Creates a image format file with the rendering of the PDF page contents.

Parameters

  • Filename : String

    The full path filename of the image file to create. The file name extension defines the file format, e.g. filename.png to create a PNG format file, filename.tif to create a TIF format file, etc.

  • DPIs : Integer

    The rendering resolution, in Dots Per Inch.

  • BKColor : unsigned short (optional)

    The page background color (ARGB format). The default value is full white, i.e. 0xFFFFFFFF.
    Creates a 24-bit image if the color is fully opaque, i.e. A=0xFF, or a 32-bit image otherwise.

  • Flags : unsigned short (optional)

    Combination of the following values:

    0x01 - Render annotations
    0x02 - Optimized for LCD display
    0x04 - Don't use native text
    0x08 - Grayscale
    0x800 - Render for printing
    0x1000 - Disable anti-aliasing on text
    0x2000 - Disable anti-aliasing on images
    0x4000 - Disable anti-aliasing on paths

RenderToImage( Integer DPIs, [Integer BKColor], [Integer Flags] ) : ImageFile

Returns a WIA ImageFile object containing the rendered image of the page contents

Parameters

IMetadataFieldsInfo Object

Provides access to the entire collection of metadata fields definitions, both standard and custom.

Remarks

 

Example

 

Properties

Methods

This object has no methods

Properties description

Count : Integer (read)

Returns the number of IFileMetadata items in the collection.

Item( Integer Index ) : IMetadataFieldInfo (read;default)

Exposes a specified IFileMetadata item from the collection.

IProgressBar Object

Provides access to the My Scripts Host GUI main progress bar.

Remarks

 

Example

 

Properties

Methods

This object has no methods

Properties description

Max : Integer (read;write)

Sets or returns the progress bar maximum position.

Min : Integer (read;write)

Sets or returns the progress bar minimum position.

Position : Integer (read;write)

Sets or returns the progress bar position.

IFloatRect Object

A simple rectangle structure object.

Remarks

 

Example

 

Properties

Methods

This object has no methods

Properties description

Bottom : Single (read;write)

 

Left : Single (read;write)

 

Right : Single (read;write)

 

Top : Single (read;write)

 

IMetadataFieldInfo Object

A metadata field information object to get information about its definition characteristics

Remarks

 

Example

 

Properties

Methods

This object has no methods

Properties description

Caption : String (read)

Returns the visible name of the property field.

PropertyName : String (read)

Returns the internal name of the property field.

IArguments Object

(WSH) - Provides access to the entire collection of command-line parameters, in the order in which they were originally entered.

Remarks

 

Example

 

Properties

Methods

Properties description

Item( Integer Index ) : String (read;default)

(WSH) - Exposes a specified item from a collection.

Length : Integer (read)

(WSH) - Returns the number of command-line parameters belonging to a script (the number of items in an argument's collection).

Methods description

Count( ) : Integer

(WSH) - Returns the number of members in the collection.

IFileMetadata Object

To read and write document metadata properties.

Remarks

 

Example

 

Properties

Methods

Properties description

Author : String (read;write)

Returns or sets the document author metadata field.

Calculated( Integer Index ) : String (read) (not used)

Returns a, index specified, calculated metadata field.

Count : Integer (read)

Returns the number of metadata items in the collection.

CreationDate : Variant (read;write)

Returns or sets the document creation date metadata field.

Creator : String (read;write)

Returns or sets the document creator metadata field.

Custom( Integer Index ) : String (read;write)

Returns or sets a document, index specified, custom metadata field.

EncryptLevel : Integer (read)

Returns the document encrypt level.

Item( Integer Index ) : Variant (read;default)

Exposes a specified metadata item from the collection.

Keywords : String (read;write)

Returns or sets the document keywords metadata field.

ModificationDate : Variant (read;write)

Returns or sets the document modification date metadata field.

Producer : String (read;write)

Returns or sets the document producer metadata field.

Subject : String (read;write)

Returns or sets the document subject metadata field.

Title : String (read;write)

Returns or sets the document title metadata field.

Version : String (read)

Returns the document version.

Methods description

CommitChanges( [Boolean DBOnly] ) : Boolean

Save metadata changes to the file.

Parameters

  • DBOnly : Boolean (optional) (not used)

    It true, the changes are not saved to the PDF. Only the database is updated.

IAttachment Object

Represents an attachment object. The root attachment is obtained from the IFileObject AttachmentRoot property.

Remarks

 

Example

The following JScript dump the names and description of all the attachments in the document.

var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;
for (var i = 0; i < pdfe.SelectedFiles.count; i++) {
    ProgressBar.position = i + 1;
    var doc = pdfe.SelectedFiles(i);
    if (doc.AttachmentRoot.Children.Count > 0) {
        pdfe.echo('>' + doc.filename, 0x0000FF);
        DumpAttachments('  ', doc.AttachmentRoot.Children);
    }
}

function DumpAttachments(parentName, Attachments) {
    if (Attachments) {
        for (var i = 0; i < Attachments.count; i++) {
            var attachment = Attachments(i);
            if (attachment.AttType == 1 /*attFile*/ ) {
                var desc = (attachment.description.length > 0) ? ' : ' + attachment.description : "";
                pdfe.echo(parentName + attachment.name + desc);
            } else {
                DumpAttachments(parentName + attachment.name + '\\', attachment.Children);
            }
        }
    }
}

Properties

Methods

Properties description

AttType : user defined type (read)

The type (attFolder=0,attFile=1) of the attachment.

Children : IAttachments (read)

A IAttachments object, that list the children, if this is a attachment of type attFolder

Description : String (read)

The text string for the attachment description that the user sees in the attachments panel

Name : String (read)

The text string for the attachment that the user sees in the attachments panel

Methods description

SaveTo( String Path ) : Boolean

Saves the attachment to an external file or folder.

Parameters

  • Path : String

    If the attachment type is of attFolder, the full path directory name were to save all the contained attachments.
    If of type attFile, can be just a full path directory name and the created file name will be the attachment name, or a full path and filename to also specify the file name to use.

IAttachments Object

Remarks

 

Example

 

Properties

Methods

This object has no methods

Properties description

Count : Integer (read)

 

Item( Integer Index ) : IAttachment (read;default)

 

IBookmarks Object

Remarks

 

Example

 

Properties

Methods

This object has no methods

Properties description

Count : Integer (read)

 

Item( Integer Index ) : IBookmark (read;default)

 

IBookmark Object

Represents a bookmark node object. The root bookmark, not visible to the user, is obtained from the IFileObject BookmarkRoot property.

Remarks

 

Example

The following JScript dump the bookmark names of the document bookmark tree.

var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;
for (var i = 0; i < pdfe.SelectedFiles.count; i++) {
    ProgressBar.position = i + 1;
    var doc = pdfe.SelectedFiles(i);
    if (doc.BookmarkRoot && doc.BookmarkRoot.Children) {
        pdfe.echo('>' + doc.filename, 0x0000FF);
        DumpBookmark(doc.BookmarkRoot, 0);
    }
}

function DumpBookmark(bookmark, index) {
    if (bookmark) {
        if (index > 0) pdfe.echo(Array(index * 3).join(" ") + bookmark.name);
        var children = bookmark.Children;
        if (children) {
            for (var i = 0; i < children.count; i++) {
                DumpBookmark(children(i), index + 1);
            }
        }
    }
}

Properties

Methods

This object has no methods

Properties description

Children : IBookmarks (read)

A IBookmarks object that list the children of this bookmark in the bookmark tree

DestPageIndex : Integer (read)

The target page, zero-based, index. Returns -1 if the target is not a page in the document or if the target could not be determined.

Name : String (read)

The text string for the bookmark that the user sees in the navigational panel

IDocumentMerger Object

A document merger object

Remarks

 

Example

The following JScript code exemplifies how to use the two different merge functions.

var Merger = pdfe.CreateDocumentMerger();
Merger.BookmarkAll1stPages = true;


//merge all selected documents odd pages
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    Merger.MergeDocument(pdfe.SelectedFiles(i).Filename,'odd');
}
Merger.EndAndSaveTo('C:\\Temp\\Merged_OddPages.pdf');

//Merge all document 1st page, passing IPDFPage objects, and at same time rotate the page 
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    var page=pdfe.SelectedFiles(i).Pages(0);
    page.Rotation=90;
    Merger.MergePage(page);
}
Merger.EndAndSaveTo('C:\\Temp\\Merged_1sPages.pdf');

Properties

Methods

Properties description

BookmarkAll1stPages : Boolean (read;write)

Sets or identifies if a bookmark, for the document first page, should always be added, even for documents without bookmarks defined.

GroupBookmarksByDocument : Boolean (read;write)

If bookmarks are kept, sets or identifies if bookmarks are grouped by merged document.

GroupLayersByDocument : Boolean (read;write)

If layers are kept, sets or identifies if layers are grouped by merged document.

KeepBookmarks : Boolean (read;write)

Sets or identifies if the document bookmarks are kept.

KeepLayers : Boolean (read;write)

Sets or identifies if the document layers are kept

LastError : String (read)

If one of the merge function returns false, this property contains the related error message.

Methods description

EndAndSaveTo( String Filename ) : Boolean

Ends the merge operation, and save the result document to the specified file name. When done, the object is ready to start another merge operation.

Parameters

MergeBlankPage( [Integer Width], [Integer Height] ) : Boolean

Merge a blank page, specifying its width and height in millimeters

Parameters

MergeDocument( String Filename, [String PagesRange] ) : Boolean

Merge a document, specifying its file name and, optionally, the pages to include.

Parameters

MergePage( IPDFPage Page ) : Boolean

Merge a document page, specifying its IPDFPage object.

Parameters

IAnnotations Object

Remarks

 

Example

 

Properties

Methods

This object has no methods

Properties description

Count : Integer (read)

 

Item( Integer Index ) : IAnnotation (read)

 

IAnnotation Object

Represents a PDF annotation. The document/page annotations are obtained from the IFileObject Annotations property.

Remarks

 

Example

 

Properties

Methods

This object has no methods

Properties description

Author : String (read)

 

Contents : String (read)

 

Date : String (read)

 

Name : String (read)

 

Rect : IFloatRect (read)

 

Type : String (read)

Any of the possible annotation types: Text, FreeText, Line, Square, Circle, Polygon, PolyLine, Highlight, Underline, Squiggly, StrikeOut, Stamp, Caret, Ink, FileAttachment, Sound, Link, Popup, Movie, Widget, Screen, PrinterMark, TrapNet, Watermark, 3D.

IClipboard Object

Remarks

 

Example

pdfe.clipboard.AsText="Hello World";
pdfe.echo(pdfe.clipboard.AsText);

Properties

Methods

This object has no methods

Properties description

AsText : String (read;write)

Get, or sets, the text content of the clipboard

(c) 2006-2021 RTT