天天看點

InDesign插件-正常功能開發-多頁PDF導入-js腳本開發-ID插件

作者:應用開發

1.算法程式

Adobe InDesign是Adobe公司的一個桌面出版 (DTP) 的應用程式,主要用于各種印刷品的排版編輯。InDesign可以将文檔直接導出為Adobe的PDF格式,而且有多語言支援。采用腳本語言自動化編碼,在學習中的一個重要功能是多頁PDF導入功能,以下源代碼僅用于學習交流,請勿用于商業用途和其它非法用途。源代碼如下所示:

//PlacePDFPages.js 
//Select the file you want to place.
var myFile = File.openDialog("Select the file you want to place", "");
//Create a dialog.
var myDialog = app.dialogs.add({name:"PDF多頁面導入",canCancel:true});
with(myDialog){
  //Add a dialog column.
  with(dialogColumns.add()){
    //Create First border panel.
    with(borderPanels.add()){
      with(dialogColumns.add()){
        staticTexts.add({staticLabel:"導入PDF從第1頁到第n頁:"});
      }
      with(dialogColumns.add()){
        //Create a number entry field.Note that this uses editvalue
        //rather than editerText (as a textBox would).
       var LastPagesNumField = realEditboxes.add({editValue:5});
      }
    }
    //Create Second border panel.
    with(borderPanels.add()){
        with(dialogColumns.add()){
          staticTexts.add({staticLabel:"PDF頁面左上角定位于X坐标(mm):"});
         }
      with(dialogColumns.add()){
        //Create a number entry field.Note that this uses editvalue
        //rather than editerText (as a textBox would).
       var TopLeftXField = realEditboxes.add({editValue:0});
      }
    }
    //Create Third border panel.
    with(borderPanels.add()){
        with(dialogColumns.add()){
          staticTexts.add({staticLabel:"PDF頁面左上角定位于Y坐标(mm):"});
         }
      with(dialogColumns.add()){
        //Create a number entry field.Note that this uses editvalue
        //rather than editerText (as a textBox would).
       var TopLeftYField = realEditboxes.add({editValue:0});
      }
    }      
  }
}
//Display the dialog box.
if(myDialog.show() == true){ 
//Get the LastPagesNum from the LastPagesNumField.
LastPagesNum = LastPagesNumField.editValue;
TopLeftX=TopLeftXField.editValue;
TopLeftY=TopLeftYField.editValue;

var myDocument = app.activeDocument;    
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;   
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;  

Locat = [TopLeftX, TopLeftY];

app.pdfPlacePreferences.pdfCrop=PDFCrop.cropMedia;  
myDocument.documentPreferences.pagesPerDocument = LastPagesNum; 
for (i=0; i<LastPagesNum; i++)
    {
        app.pdfPlacePreferences.pageNumber = i+1;
        curPage=app.activeDocument.pages[i];  
        curPage.place(File(myFile),Locat); 
         }
}
else{
//Remove the dialog box from memory.
myDialog.destroy();
}
           

2.作者答疑

如有疑問,請留言。

提示: 作者知了-聯系方式1

提示: 作者知了-聯系方式2

繼續閱讀