QX.js Scripting Guide

Working with Images

QXML for image

Image is represented by the <qx-img> node. It contains the following attributes:

 

Attribute

Value

Description

src

text

Source of Image, i.e, the path from where the image is to be taken

src#page=

text

Import particular page of a PDF file

src#page&boundingbox=

mediabox | cropbox | bleedbox | trimbox

Bounding box of PDF file

mediabox

Uses the size of the page, not including space for bleeds or registration marks.

cropbox

Uses the size of the page plus space for any specified bleeds and space allotted for registration marks. It equals the size of the layout space from the PDF Boxer XT software standpoint.

bleedbox

Uses the size of the page plus space for bleeds.

trimbox

Uses the size of the page after trimming is done. This option does not include registration marks and is unaffected by any bleeds applied to the layout space when the PDF is created.

Import image in picture box

To import an image in a picture box:

  1. Get the DOM of the active layout.

  2. Get the desired <qx-box> and <qx-img> node.

  3. Set the 'src' attribute to 'file:///C:/test.jpg'.

Sample JavaScript:

var layout = app.activeLayoutDOM();
var boxes = layout.getElementsByTagName('qx-box');
var images = boxes[0].getElementsByTagName('qx-img');
images[0].setAttribute('src','file:///C:/test.jpg');

Change existing image

To change an existing image:

  1. Get the DOM of the active layout.

  2. Get the desired <qx-box> and <qx-img> node.

  3. Change the 'src' attribute to 'file:///C:/new_test.jpg'.

Sample JavaScript:

var layout = app.activeLayoutDOM();
var boxes = layout.getElementsByTagName('qx-box');
var images = boxes[0].getElementsByTagName('qx-img');
images[0].setAttribute('src','file:///C:/new_test.jpg');

Apply Offsets

Offset across

To apply offset across:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxOffsetAcross styling property to '0.5in'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxOffsetAcross='0.5in';

Offset down

To apply offset down:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxOffsetDown styling property to '0.5in'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxOffsetDown='0.5in';

Apply transform

Scale horizontally

To scale horizontally:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxTransform styling property to 'scaleX(0.5)'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxTransform='scaleX(0.5)';

Scale vertically

To apply scale vertically:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxTransform styling property to 'scaleY(0.5)'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxTransform='scaleY(0.5)';

Rotate

To apply rotate:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxTransform styling property to 'rotate(30deg)'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxTransform='rotate(30deg)';

Skew

To apply skew:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxTransform styling property to 'skew(40deg)'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxTransform='skew(40deg)';

Apply color

To apply color to a monochrome image:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxColor styling property to 'cyan'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxColor='cyan';

Apply shade

To apply shade to a monochrome image:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxShade styling property to '0.7'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxShade='0.7';

    Can be specified in the 0 - 1 range (0=0% and 1 = 100%).

    Example values:  0 = 0%, 0.25 = 25%, 0.50 = 50% and 1 = 100%.

Apply opacity

To apply opacity to a monochrome image:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxOpacity styling property to '0.9'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxOpacity='0.9';

    Can be specified in the 0 - 1 range (0=0% and 1 = 100%).

    Example values:  0 = 0%, 0.25 = 25%, 0.50 = 50% and 1 = 100%.

Apply mix blend mode

To apply mix blend mode to an image:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxMixBlendMode styling property to 'darken'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxMixBlendMode='darken';

Apply background color

To apply background color to a monochrome image:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxBackgroundColor styling property to 'magenta'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxBackgroundColor='magenta';

Apply background shade

To apply background shade to a monochrome image:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxBackgroundShade styling property to '0.8'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxBackgroundShade='0.8';

    Can be specified in the 0 - 1 range (0=0% and 1 = 100%).

    Example values:  0 = 0%, 0.25 = 25%, 0.50 = 50% and 1 = 100%.

Apply background opacity

To apply background opacity to a monochrome image:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Get the <qx-img> node.

  4. Set the qxBackgroundOpacity styling property to '0.5'.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var images = boxes[0].getElementsByTagName('qx-img');
    images[0].style.qxBackgroundOpacity='0.5';

    Can be specified in the 0 - 1 range (0=0% and 1 = 100%).

    Example values:  0 = 0%, 0.25 = 25%, 0.50 = 50% and 1 = 100%.

Flip image vertically

To apply flip image vertically:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Set the qxImgFlipVertical styling property to 'true'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    boxes.style.qxImgFlipVertical='true';

Flip image horizontally

To flip image horizontally:

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Set the qxImgFlipHorizontal styling property to 'true'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    boxes.style.qxImgFlipHorizontal='true';

Suppress output of image

To suppress output of image are:-

  1. Get the DOM of the active layout.

  2. Get the <qx-box> node .

  3. Set the qxImgSuppressOutput styling property to 'true'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    boxes.style.qxImgSuppressOutput='true';