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
Arguments Property | Clipboard Property | FullName Property | Host Property | Interactive Property | MetadataFieldsInfo Property | OpenDialog Property | ProgressBar Property | SaveDialog Property | ScriptFullName Property | ScriptName Property | SelectedFiles Property | Version Property
Methods
Alert Method | BringWindowToFront Method | ConnectObject Method | CreateDocumentMerger Method | CreateFileObject Method | CreateObject Method | DialogBox Method | Echo Method | MessageBox Method | Quit Method | Sleep Method | VarToStr Method
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
- msg : String
BringWindowToFront( unsigned short hWnd, [Boolean KeepAlwaysOnTop] )
Brings the specified window to the top of the Z order.
Parameters
- hWnd : unsigned short
- KeepAlwaysOnTop : Boolean (optional)
(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
- Filename : String
(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"); }
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.
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
Annotations Property | AttachmentRoot Property | BookmarkRoot Property | DateLastModified Property | EmbeddedFiles Property | FileSize Property | Filename Property | Locked Property | Metadata Property | NumPages Property | Pages Property
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
IPDFPages Object
The entire collection of pages of the document.
Remarks
Example
Properties
Methods
Properties description
Methods description
IPDFPage Object
Represents a page object in the document.
Remarks
Example
Properties
ArtBox Property | BleedBox Property | CropBox Property | Height Property | MediaBox Property | Rotation Property | Text Property | TextEx Property | TrimBox Property | Width Property
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
Returns a WIA ImageFile object containing the rendered image of the page contents
Parameters
- DPIs : Integer
Same as equivalent parameter for the RenderToFile method
- BKColor : Integer (optional)
Same as equivalent parameter for the RenderToFile method
- Flags : Integer (optional)
Same as equivalent parameter for the RenderToFile method
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
IFloatRect Object
A simple rectangle structure object.
Remarks
Example
Properties
Methods
This object has no methods
IMetadataFieldInfo Object
A metadata field information object to get information about its definition characteristics
Remarks
Example
Properties
Methods
This object has no methods
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
IFileMetadata Object
To read and write document metadata properties.
Remarks
Example
Properties
Author Property | Calculated Property | Count Property | CreationDate Property | Creator Property | Custom Property | EncryptLevel Property | Item Property | Keywords Property | ModificationDate Property | Producer Property | Subject Property | Title Property | Version Property
Methods
Properties description
Author : String (read;write)
Returns or sets the document author metadata field.
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.
Returns or sets a document, index specified, custom metadata field.
EncryptLevel : Integer (read)
Returns the document encrypt level.
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
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
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
IBookmark Object
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
BookmarkAll1stPages Property | GroupBookmarksByDocument Property | GroupLayersByDocument Property | KeepBookmarks Property | KeepLayers Property | LastError Property
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
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
- Filename : String
Merge a blank page, specifying its width and height in millimeters
Parameters
Merge a document, specifying its file name and, optionally, the pages to include.
Parameters
IAnnotations Object
Remarks
Example
Properties
Methods
This object has no methods
Properties description
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