【发布时间】:2014-01-08 16:14:17
【问题描述】:
我正在尝试编写一个脚本来执行数据合并,然后是查找/替换、页面添加,最后是导出。我可以让它执行所需的合并和查找/替换。当我手动添加新页面时,我通常选择页面窗口中的第一页,然后单击底部的添加新页面。这样做会使之后的每一页变为 2 页。我不知道如何在脚本中执行此操作,我在下面尝试的方法无效。它会在文档末尾添加一个新页面。
app.activeDocument.pages.item(0).select();
app.activeDocument.pages.add();
合并后,编辑变得非常慢,我添加或删除每个字母需要 15-20 个。我发现像您期望的那样对其进行编辑的唯一方法是将其导出为 IDML 格式,然后重新打开它InDesign 中的文件。我找不到太多关于通过 javascript 中的脚本导出的信息。我接下来打算尝试的是:app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, newDoc, false); 但我不知道这是否可行。我对 InDesign 中的脚本非常陌生。我正在使用 InDesign CS5.5,这是迄今为止的整个脚本:
main();
function main()
{
//Possibly let the user go find and choose a file
//var mergeTemplate = File.openDialog();
//var myDocument = app.open(mergeTemplate);
//Open the template file to be used by the data merge.
var myDocument = app.open(File("Macintosh HD/Users/Christian/Desktop/InDesign_Data_Merge/MMM14 Template_v1.indd"));
//Load the data source
var myDataSource = File("Macintosh HD/Users/Christian/Desktop/InDesign_Data_Merge/MMM v1.mer");
myDocument.dataMergeProperties.selectDataSource(myDataSource);
myDocument.dataMergeProperties.mergeRecords();
//Save the document under a new name for later use.
app.activeDocument.save(File("Macintosh HD/Users/Christian/Desktop/InDesign_Data_Merge/DataMerge_MMM.indd"));
//Close the document, NOT saving original template, so the original file is not destroyed or overwritten.
myDocument.close(SaveOptions.no);
//Find line break placeholder and replace with line break
findReplace ("$$", "^n");
//Find the tab placeholder and replace with tab
findReplace ("##", "^t");
//Select the first page of the document
//app.activeDocument.pages.item(0).select();
//Add another page to make the document print on both sides, like an open book
//app.activeDocument.pages.add();
//export to IDML
//exportIDML();
}
function findReplace(findVal,replaceVal)
{
// Clear the find/change text preferences.
app.findTextPreferences = NothingEnum.NOTHING;
app.changeTextPreferences = NothingEnum.NOTHING;
// Set the find options
app.findChangeTextOptions.caseSensitive = false;
app.findChangeTextOptions.includeFootnotes = false;
app.findChangeTextOptions.includeHiddenLayers = false;
app.findChangeTextOptions.includeLockedLayersForFind = false;
app.findChangeTextOptions.includeLockedStoriesForFind = false;
app.findChangeTextOptions.includeMasterPages = false;
app.findChangeTextOptions.wholeWord = false;
// Search the document for the string findVal
app.findTextPreferences.findWhat = findVal;
// Change it to the string replaceVal
app.changeTextPreferences.changeTo = replaceVal;
// Perform the search-and-replace operation
app.activeDocument.changeText();
}
function exportIDML()
{
var newDoc = app.open(File("Macintosh HD/Users/Christian/Desktop/InDesign_Data_Merge/DataMerge_MMM.indd"));
app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, newDoc, false);
}
编辑: 另一个帖子将我带到了这个网站jongware.mit.edu,但我不知道如何开始在这里搜索我需要的东西?
【问题讨论】:
-
关于“模板”
MMM14 Template_v1.indd的小提示:如果您将其保存为“模板”(在“另存为”对话框中的“格式”下),或者只是将其扩展名更改为indt,您将find ID 默认打开一个副本。
标签: javascript scripting export adobe-indesign