Variables using JavaScript: pdfToolbox objects and methods
This article provides an overview of all JavaScript objects and methods that are specific to pdfToolbox Variables. It is the same information that can be displayed in the Script editor of pdfToolbox.
app Returns the global application object.
app.requires(key) Defines a variable key with default value 0 that is required by the current script.
Example:
app.requires("myvar")
app.requires(key,value) Defines a variable key and its default value that is required by the current script.
Example:
app.requires("myvar",10)
app.requires(key,value,label) Defines a variable key and its default value and a display name (label) that is required by the current script.
Example:
app.requires("myvar",10,"Input value for myvar")
app.name Returns the application name.
app.version Returns the application version string.
app.vars Returns the var objects containing all variables defined in the current context.
app.vars.varkey Returns the value of the variable "varkey" if that exists in app.vars.
Example:
app.vars.varname
app.doc Retuns the doc object for the current PDF document or 'undefined' if no PDF is open.
app.doc.info Returns the docinfo object containing all document info entries of the current PDF document.
app.doc.path Returns the full platform dependent file path of the current pdf document.
app.doc.documentFileName Returns the file name of the current PDF document.
app.doc.numPages Returns the number of pages of the current PDF document.
app.doc.getPageBox() Returns an array containing the left, top, right and bottom coordinates of the TrimBox of the first page in pt.
app.doc.getPageBox(pageBox) Returns an array containing the left, top, right and bottom coordinates of the specified page box of the first page in pt. 'pageBox' must be one of "Art", "Bleed", "Crop", "Trim" and "Media".
Example:
app.doc.getPageBox("Trim")
app.doc.getPageBox(pageBox,pageNumber) Returns an array containing the left, top, right and bottom coordinates of the specified page box of the specified page in pt. 'pageBox' must be one of "Art", "Bleed", "Crop", "Trim" and "Media".
Example:
app.doc.getPageBox("Trim",0)
app.doc.getPageBox(pageBox,pageNumber,precision) Returns an array containing the left, top, right and bottom coordinates of the specified page box of the specified page with the given precision in pt. 'pageBox' must be one of Art, Bleed, Crop, Trim and Media.
Example:
app.doc.getPageBox("Trim",0,2)
app.doc.getPageRotation() Returns the page rotation of the first page.
app.doc.getPageRotation(pageNumber) Returns the page rotation of the specified page.
Example:
app.doc.getPageRotation(0)
app.doc.pages Returns an array with page objects for the current PDF document.
app.doc.pages[i].inks Returns an array of inks used by on the page.
Example:
app.doc.pages[0].inks
app.doc.pages[i].inks[j].name Returns the name of the ink.
Example:
app.doc.pages[0].inks[0].name
app.doc.pages[i].getPageBox() Returns an array containing the left, top, right and bottom coordinates of the TrimBox of the specified page box in pt.
Example:
app.doc.pages[0].getPageBox()
app.doc.pages[i].getPageBox(pageBox) Returns an array containing the left, top, right and bottom coordinates of the specified page box in pt. 'pageBox' must be one of Art, Bleed, Crop, Trim and Media.
Example:
app.doc.pages[0].getPageBox("Trim")
app.doc.pages[i].getPageBox(pageBox,precision) Returns an array containing the left, top, right and bottom coordinates of the specified page box with the given precision in pt. 'pageBox' must be one of Art, Bleed, Crop, Trim and Media.
Example:
app.doc.pages[0].getPageBox("Trim",2)
app.doc.pages[i].getPageRotation() Returns the page rotation of the page.
app.doc.xmp Returns a XMP object for the document XMP metadata of the current PDF document.
app.doc.xmp.getProperty(ns,property) Returns the value of the specified property in the specified namespace or 'undefined' if the property does not exists. 'ns' must be the full namespace uri. For namespaces defined in the XMP spec the predfeined namespace prefix can be used as well.
Examples:
app.doc.xmp.getProperty("http://purl.org/dc/elements/1.1/","format")
app.doc.xmp.getProperty("dc","format")
app.doc.metadata Returns the document XMP metada as plain XML
app.doc.result Returns a preflight result object or 'undefined' if no preflight result is available. A preflight result is only available inside process plans if a profile or check was executed in a previous step.
app.doc.result.hits Returns information about a previous preflight result.
app.doc.result.hits.numErrors Returns the number of errors of a prvious preflight result.
app.doc.result.hits.numWarnings Returns the number of warnings of a prvious preflight result.
app.doc.result.hits.numInfos Returns the number of info hits of a prvious preflight result.
app.doc.result.getCheckByID(checkID) Returns a check object for the specified check ID. app.doc.result.checks[i].id should be used in the Script editor evaluation in order to identify the proper ID for a check.
Example:
app.doc.result.getCheckByID(Re29eb8cfa87a9b06ebac2ac1aa013a7b)
app.doc.result.checks Returns an array of Check objects for the previous preflight result.
app.doc.result.checks.length Returns the lenght of the array of Check objects for the previous preflight result.
app.doc.result.checks[i].id Returns the check ID of the specified check for the previous preflight result.
Example:
app.doc.result.checks[0].id
app.doc.result.checks[i].name Returns the display name of the specified check of the previous preflight result.
Example:
app.doc.result.checks[0].name
app.doc.result.checks[i].severity Returns the severity of the specified check for the previous preflight result: 1: Info, 2: Warning, 3: Error.
Example:
app.doc.result.checks[0].severity
app.doc.result.checks[i].numHits Returns the number of hits of the specified check for the previous preflight result.
Example:
app.doc.result.checks[0].numHits
app.doc.result.checks[i].pageNumbers Returns an array of page numbers (starting with 0) for pages that had hits with the specified check for the previous preflight result.
Example:
app.doc.result.checks[0].pageNumbers