Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Specify placement of images using script

New Here ,
Mar 20, 2019 Mar 20, 2019

I'm working on a new product that utilizes HP's Indigo Printer. Because the printer only uses one size of paper, if we can fit multiple projects on one sheet of paper we can print much more economically and save our clients a lot of money. I know how to use scripts to place multiple images on separate pages but as far as I know, there's no way to specify that they need to be placed differently on a left page as opposed to a right page.

I need a script that would allow me to, for example, specify left justification on a left page, and right justification on the right page. This way when the paper is printed on the opposite side the positioning

is correct.

Ideally, I need a way to just specify an exact placement for each page, left and right, multiple times so that I can easily layout multiple projects on a page, like the image I attached.

Any help or direction would be greatly appreciated!

script_example.jpg

TOPICS
Scripting
399
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Mar 25, 2019 Mar 25, 2019

Hi there,

Try this below code for your reference...

var myDoc = app.documents[0];

var page = myDoc.pages[1];

var folder = 'C:/Users/sunily/Desktop/ProjectImages';

placeAllImages(page, folder);

/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////

function placeAllImages(myCurrentPage, myFolderPath){

    var allFiles = Folder(myFolderPath).getFiles('*png');

    for(v

...
Translate
Advocate ,
Mar 25, 2019 Mar 25, 2019
LATEST

Hi there,

Try this below code for your reference...

var myDoc = app.documents[0];

var page = myDoc.pages[1];

var folder = 'C:/Users/sunily/Desktop/ProjectImages';

placeAllImages(page, folder);

/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////

function placeAllImages(myCurrentPage, myFolderPath){

    var allFiles = Folder(myFolderPath).getFiles('*png');

    for(var i = 0; i < allFiles.length; i++){

        var myImage = myCurrentPage.place(allFiles);

        if(allFiles.name.toString().toLowerCase().indexOf('projecta') != -1){

            if(myCurrentPage.side.toString().toLowerCase().indexOf('left') != -1){

                var myX_Y = getCo_Ordinates(myImage, myCurrentPage, 0);

                }

            else if(myCurrentPage.side.toString().toLowerCase().indexOf('right') != -1){

                var myX_Y = getCo_Ordinates(myImage, myCurrentPage, 1);

                }

            }

        else if(allFiles.name.toString().toLowerCase().indexOf('projectb') != -1){

            if(myCurrentPage.side.toString().toLowerCase().indexOf('left') != -1){

                var myX_Y = getCo_Ordinates(myImage, myCurrentPage, 2);

                }

            else if(myCurrentPage.side.toString().toLowerCase().indexOf('right') != -1){

                var myX_Y = getCo_Ordinates(myImage, myCurrentPage, 3);

                }

            }

        else if(allFiles.name.toString().toLowerCase().indexOf('projectc') != -1){

            if(myCurrentPage.side.toString().toLowerCase().indexOf('left') != -1){

                var myX_Y = getCo_Ordinates(myImage, myCurrentPage, 4);

                }

            else if(myCurrentPage.side.toString().toLowerCase().indexOf('right') != -1){

                var myX_Y = getCo_Ordinates(myImage, myCurrentPage, 5);

                }

            }

        myImage[0].parent.move(myX_Y);

        }

    }

///////////////////////////////////

function getCo_Ordinates(img, page, i){

    var x = 0;

    var y = 0;

    var left = page.marginPreferences.left;

    var right = page.marginPreferences.right;

    var top = page.marginPreferences.top;

    var bottom = page.marginPreferences.bottom;

    var docHeight = myDoc.documentPreferences.pageHeight;

    var docWidth = myDoc.documentPreferences.pageWidth;

    var imgGB = img[0].parent.geometricBounds;

    var imgWidth = imgGB[3]-imgGB[1];

    var imgHeight = imgGB[2]-imgGB[0];

    /////////////////////////  you can specify here the x & y co-ordinates where to move your object --------------------------

    switch (i){

        case 0:

            x = 0;

            y = 0;

            break;

        case 1:

            x = docWidth-imgWidth;

            y = 0;

            break;

        case 2:

            x = docWidth-imgWidth-right;

            y = top;

            break;

        case 3:

            x = left;

            y = top;

            break;

        case 4:

            x = docWidth-imgWidth-right;

            y = docHeight-bottom-imgHeight;

            break;

        case 5:

            x = left;

            y = docHeight-bottom-imgHeight;

            break;

        case 6:

            x = 0;

            y = 0;

            break;

        }

    return [x,y];

    }

Best

Sunil

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines