Highlighted

Import multiple pdf into indesign file

Enthusiast ,
Feb 26, 2013

Copy link to clipboard

Copied

Hi ALL,

Trying Script:

By using inbuilt script "PlaceMultipagePDF.jsx" import all the pdf in the selected folder (i.e., 111.pdf, 222.pdf, 333.pdf) in the "test.indt"

But my requirement:

1. open test.indt file and import 111.pdf alone after that close with any file naming.

2. open test.indt file and import 222.pdf after that close with any file naming.

3. open test.indt file and import 333.pdf after that close with any file naming.

Trying Script Code:

var myFolder = Folder.selectDialog("Select the folder containing the Indesign Files", "");

var myIFiles = myFolder.getFiles("*.indt")

for(j=0; j<myIFiles.length; j++)

{

    var myIndesignFile = myIFiles

    app.open(myIndesignFile)

   

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

   

var myFolder = Folder.selectDialog("Select the folder containing the PDF Files", "");   //Please check this line

var myFiles = myFolder.getFiles("*.pdf")

for(i=0; i<myFiles.length-1; i++)

{

    var myPDFFile= myFiles

    var myDocument = app.documents[0];

        if(myDocument == true){

            var myPage = myChoosePage(myDocument);

        }

        else{

            myPage = myDocument.pages.item(0);

        }

        myPlacePDF(myDocument, myPage, myPDFFile);

    }

}

function myChoosePage(myDocument){

    var myPageNames = new Array;

    //Get the names of the pages in the document

    for(var myCounter = 0; myCounter < myDocument.pages.length;myCounter++){

        myPageNames.push(myDocument.pages.item(myCounter).name);

    }

    return myPage;

}

function myPlacePDF(myDocument, myPage, myPDFFile){

    var myPDFPage;

    app.pdfPlacePreferences.pdfCrop = PDFCrop.cropMedia;

    var myCounter = 1;

    var myBreak = false;

    while(myBreak == false){

        if(myCounter > 1){

            myPage = myDocument.pages.add(LocationOptions.after, myPage);

        }

        app.pdfPlacePreferences.pageNumber = myCounter;

        myPDFPage = myPage.place(File(myPDFFile), [0,0])[0];         //check this line

        if(myCounter == 1){

            var myFirstPage = myPDFPage.pdfAttributes.pageNumber;

        }

        else{

            if(myPDFPage.pdfAttributes.pageNumber == myFirstPage){

                myPage.remove();

                myBreak = true;

            }

        }

        myCounter = myCounter + 1;

    }

}

Can anyone give solution for my question.

Thanks

BEGINNER

Hi,

Try b/m code

var myFolder = Folder.selectDialog("Select the folder containing the Indesign Files", "");

var myIFiles = myFolder.getFiles("*.indt")

for(j=0; j<myIFiles.length; j++)

{

    var myIndesignFile = myIFiles;

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

    var myFolder = Folder.selectDialog("Select the folder containing the PDF Files", "");   //Please check this line

    var myFiles = myFolder.getFiles("*.pdf")

    for(i=0; i <= myFiles.length-1; i++)

    {

        app.open(myIndesignFile);

        var myPDFFile= myFiles;

        var myDocument = app.documents[0];       

        if(myDocument == true){

            var myPage = myChoosePage(myDocument);

            }

        else{

            myPage = myDocument.pages.item(0);

            }

        myPlacePDF(myDocument, myPage, myPDFFile);

        if(app.activeDocument.modified == true){           

            app.activeDocument.save(new File(String(myFiles).replace('.pdf','') + ".indd"));

            app.activeDocument.save();

            app.activeDocument.close()

            }

        }

    }

--

Thanks

Bala...

TOPICS
Scripting

Views

1.9K

Likes

Translate

Translate

Report

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

Import multiple pdf into indesign file

Enthusiast ,
Feb 26, 2013

Copy link to clipboard

Copied

Hi ALL,

Trying Script:

By using inbuilt script "PlaceMultipagePDF.jsx" import all the pdf in the selected folder (i.e., 111.pdf, 222.pdf, 333.pdf) in the "test.indt"

But my requirement:

1. open test.indt file and import 111.pdf alone after that close with any file naming.

2. open test.indt file and import 222.pdf after that close with any file naming.

3. open test.indt file and import 333.pdf after that close with any file naming.

Trying Script Code:

var myFolder = Folder.selectDialog("Select the folder containing the Indesign Files", "");

var myIFiles = myFolder.getFiles("*.indt")

for(j=0; j<myIFiles.length; j++)

{

    var myIndesignFile = myIFiles

    app.open(myIndesignFile)

   

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

   

var myFolder = Folder.selectDialog("Select the folder containing the PDF Files", "");   //Please check this line

var myFiles = myFolder.getFiles("*.pdf")

for(i=0; i<myFiles.length-1; i++)

{

    var myPDFFile= myFiles

    var myDocument = app.documents[0];

        if(myDocument == true){

            var myPage = myChoosePage(myDocument);

        }

        else{

            myPage = myDocument.pages.item(0);

        }

        myPlacePDF(myDocument, myPage, myPDFFile);

    }

}

function myChoosePage(myDocument){

    var myPageNames = new Array;

    //Get the names of the pages in the document

    for(var myCounter = 0; myCounter < myDocument.pages.length;myCounter++){

        myPageNames.push(myDocument.pages.item(myCounter).name);

    }

    return myPage;

}

function myPlacePDF(myDocument, myPage, myPDFFile){

    var myPDFPage;

    app.pdfPlacePreferences.pdfCrop = PDFCrop.cropMedia;

    var myCounter = 1;

    var myBreak = false;

    while(myBreak == false){

        if(myCounter > 1){

            myPage = myDocument.pages.add(LocationOptions.after, myPage);

        }

        app.pdfPlacePreferences.pageNumber = myCounter;

        myPDFPage = myPage.place(File(myPDFFile), [0,0])[0];         //check this line

        if(myCounter == 1){

            var myFirstPage = myPDFPage.pdfAttributes.pageNumber;

        }

        else{

            if(myPDFPage.pdfAttributes.pageNumber == myFirstPage){

                myPage.remove();

                myBreak = true;

            }

        }

        myCounter = myCounter + 1;

    }

}

Can anyone give solution for my question.

Thanks

BEGINNER

Hi,

Try b/m code

var myFolder = Folder.selectDialog("Select the folder containing the Indesign Files", "");

var myIFiles = myFolder.getFiles("*.indt")

for(j=0; j<myIFiles.length; j++)

{

    var myIndesignFile = myIFiles;

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

    var myFolder = Folder.selectDialog("Select the folder containing the PDF Files", "");   //Please check this line

    var myFiles = myFolder.getFiles("*.pdf")

    for(i=0; i <= myFiles.length-1; i++)

    {

        app.open(myIndesignFile);

        var myPDFFile= myFiles;

        var myDocument = app.documents[0];       

        if(myDocument == true){

            var myPage = myChoosePage(myDocument);

            }

        else{

            myPage = myDocument.pages.item(0);

            }

        myPlacePDF(myDocument, myPage, myPDFFile);

        if(app.activeDocument.modified == true){           

            app.activeDocument.save(new File(String(myFiles).replace('.pdf','') + ".indd"));

            app.activeDocument.save();

            app.activeDocument.close()

            }

        }

    }

--

Thanks

Bala...

TOPICS
Scripting

Views

1.9K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 26, 2013 1
Participant ,
Feb 27, 2013

Copy link to clipboard

Copied

Hi,

Try b/m code

var myFolder = Folder.selectDialog("Select the folder containing the Indesign Files", "");

var myIFiles = myFolder.getFiles("*.indt")

for(j=0; j<myIFiles.length; j++)

{

    var myIndesignFile = myIFiles;

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

    var myFolder = Folder.selectDialog("Select the folder containing the PDF Files", "");   //Please check this line

    var myFiles = myFolder.getFiles("*.pdf")

    for(i=0; i <= myFiles.length-1; i++)

    {

        app.open(myIndesignFile);

        var myPDFFile= myFiles;

        var myDocument = app.documents[0];       

        if(myDocument == true){

            var myPage = myChoosePage(myDocument);

            }

        else{

            myPage = myDocument.pages.item(0);

            }

        myPlacePDF(myDocument, myPage, myPDFFile);

        if(app.activeDocument.modified == true){           

            app.activeDocument.save(new File(String(myFiles).replace('.pdf','') + ".indd"));

            app.activeDocument.save();

            app.activeDocument.close()

            }

        }

    }

--

Thanks

Bala...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 27, 2013 1
Enthusiast ,
Feb 27, 2013

Copy link to clipboard

Copied

Hi Bala,

Thanks a lot.....

Its really helpful for me.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 27, 2013 0
New Here ,
Oct 21, 2020

Copy link to clipboard

Copied

I made a few modifications to make this work for me. 

  • Added array indexes where needed
  • PDFs are appended to new pages at the end of the document instead of all being added to the first page

 

function myPlacePDF(myDocument, myPage, myPDFFile){

    var myPDFPage;
    app.pdfPlacePreferences.pdfCrop = PDFCrop.cropMedia;
    var myCounter = 1;
    var myBreak = false;

    while(myBreak == false){
        if(myCounter > 1){
            myPage = myDocument.pages.add(LocationOptions.after, myPage);
        }
        app.pdfPlacePreferences.pageNumber = myCounter;
        myPDFPage = myPage.place(File(myPDFFile), [0,0])[0];         //check this line
        if(myCounter == 1){
            var myFirstPage = myPDFPage.pdfAttributes.pageNumber;
        }
        else{
            if(myPDFPage.pdfAttributes.pageNumber == myFirstPage){
                myPage.remove();
                myBreak = true;
            }
        }
        myCounter = myCounter + 1;
    }
}

var myFolder = Folder.selectDialog("Select the folder containing the Indesign Files", "");

var myIFiles = myFolder.getFiles("*.indd");
var files_placed = 0;

for(j=0; j<myIFiles.length; j++)
{

    var myIndesignFile = myIFiles[j];
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
    var myFolder = Folder.selectDialog("Select the folder containing the PDF Files", String(myIndesignFile));   //Please check this line
    var myFiles = myFolder.getFiles("*.pdf");

    for(i=0; i < myFiles.length; i++)
    {
        app.open(myIndesignFile);
        var myPDFFile= myFiles[i];
        var myDocument = app.documents[0];       
        new_page = myDocument.pages.add();

        myPlacePDF(myDocument, new_page, myPDFFile);
        files_placed++;
    }
}

alert("Complete. " + files_placed + " files placed.");

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 21, 2020 0
Community Beginner ,
Feb 10, 2018

Copy link to clipboard

Copied

Hi Bala,

Please help!

open test.indt file and import pdf alone with there trim size after that close with crop size placed pdf file naming.

Example:

  • a.pdf 1 page trim 4X6" crop 4.5X6.425"
  • b.pdf 2 pages trim 5X7.234" crop 5.427X7.528"

I have folder with different size 1, 2 or 3 page pdfs. I need to place in .indt file with respective pdf trim size with cropped size placed.

I am getting error message in indesign CC15 and CC18.

Thanks

Sachin

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 10, 2018 0