Skip to content

JavaScript Document Manipulation Examples

Get the name of the document

await publisher.getObject("document.name");
editorObject.GetObject("document.name");

Get the XML of the document currently in the editor

await publisher.executeFunction("document", "GetTempXML");
editorObject.ExecuteFunction("document", "GetTempXML");

Load a document in to the editor

/* publisherDocument can be either a document ID or document XML*/
const publisherDocument = `document id or xml`;
await publisher.executeFunction('document','OpenDocumentFromXml', publisherDocument);
/* publisherDocument can be either a document ID or document XML*/
const publisherDocument = `document id or xml`;
editorObject.ExecuteFunction('document','OpenDocumentFromXml', publisherDocument);

You can optionally include a Workspace ID and/or View Preferences ID to load with the document

const publisherDocument = `document id or xml`;
const workspaceID = `itemID of Workspace`;
const viewPreferencesID = `itemID of View Preferences`;
await publisher.executeFunction('document','OpenDocumentFromXml', publisherDocument, workspaceID, viewPreferencesID);
const publisherDocument = `document id or xml`;
const workspaceID = `itemID of Workspace`;
const viewPreferencesID = `itemID of View Preferences`;
editorObject.ExecuteFunction('document','OpenDocumentFromXml', publisherDocument, workspaceID, viewPreferencesID);

Save document

await publisher.executeFunction("document", "Save");
editorObject.ExecuteFunction("document", "Save");

Rotate document

await publisher.setProperty("document.viewPreferences", "rotateView", 180);
editorObject.SetProperty("document.viewPreferences", "rotateView", 180);

Freeze undo manager

/* If set to true, changes are no longer tracked */
await publisher.setProperty("doc.undoManager", "holdChanges", true);
/* If set to true, changes are no longer tracked */
editorObject.SetProperty("doc.undoManager", "holdChanges", true);

Get mouse position

/* Returns the x, y and current page of the mouse cursor */
await publisher.executeFunction("document", "GetMousePosition");
/* Returns the x, y and current page of the mouse cursor */
editorObject.ExecuteFunction("document", "GetMousePosition");