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

Import multiple pdf into indesign file

Enthusiast ,
Feb 26, 2013 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

TOPICS
Scripting

Views

2.4K

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
community guidelines

correct answers 1 Correct answer

Participant , Feb 27, 2013 Feb 27, 2013

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++

...

Votes

Translate

Translate
Participant ,
Feb 27, 2013 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...

Votes

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
community guidelines
Enthusiast ,
Feb 27, 2013 Feb 27, 2013

Copy link to clipboard

Copied

Hi Bala,

Thanks a lot.....

Its really helpful for me.

Votes

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
community guidelines
New Here ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

LATEST

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.");

 

 

Votes

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
community guidelines
Community Beginner ,
Feb 10, 2018 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

Votes

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
community guidelines