【问题标题】:Issue with InDesign startup script not loading images from XML importInDesign 启动脚本无法从 XML 导入加载图像的问题
【发布时间】:2016-07-21 15:06:23
【问题描述】:

我正在尝试在加载文档时从启动脚本自动执行 XML 导入。我成功地填充了大部分内容,但图像被忽略了。当我通过 UI 或通过手动脚本执行手动“导入 XML”时,一切正常,包括图像。

以下是我的手动脚本:

var myDocument = app.activeDocument;
var xmlFile = File('/c/Full/Path/To/data.xml');

myDocument.importXML(xmlFile);

但目标是在启动时完成。下面是我的启动脚本:

#targetengine "session"

app.addEventListener('afterOpen', function(myEvent) {
    if (myEvent.target.constructor.name !== 'Document') {
        return;
    }

    var myDocument = myEvent.target;
    var xmlFile = File('/c/Full/Path/To/data.xml');

    myDocument.importXML(xmlFile);
});

下面是图片的 XML 标签:

<Image href="file:///C:/Full/Path/To/Image/02.png" />

我想知道'afterOpen' 事件回调是否存在问题,这就是它使用相同方法手动工作但在启动脚本中没有的原因。

【问题讨论】:

    标签: javascript xml adobe-indesign extendscript


    【解决方案1】:

    我能够通过完全避免事件侦听器来解决这个问题。

    main();  
    
    function main () {  
    
        // create a path for a file object  
        var curFile = File('/c/Path/To/file.indd');  
        var xmlFile = File('/c/Path/To/data.xml');  
    
        // close app if files don't exist  
        if (!curFile.exists || !xmlFile.exists) {  
            app.quit(SaveOptions.NO);  
        }  
    
        // open the file  
        var curDoc = app.open(curFile);  
    
        // import the xml  
        curDoc.importXML(xmlFile);  
    
        // create a new file object  
        var pdfFile = new File(curFile.parent + '/' + curFile.name + '.pdf');  
    
        // export to pdf  
        curDoc.exportFile(ExportFormat.PDF_TYPE, pdfFile);  
    
        // close app  
        app.quit(SaveOptions.NO);  
    
    }
    

    【讨论】:

    • 为什么要关闭应用?
    • 我不希望 InDesign 在不需要时占用资源。我有一个 PowerShell 脚本,用于侦听特定目录中 XML 文件的更改,并在检测到更改时启动 InDesign。然后启动脚本打开必要的文档,进行导入,导出为 PDF,然后关闭应用程序。
    • 可以解释一下。
    猜你喜欢
    • 1970-01-01
    • 2016-06-13
    • 2019-07-31
    • 1970-01-01
    • 2020-03-20
    • 2013-10-12
    • 1970-01-01
    • 2014-08-30
    • 1970-01-01
    相关资源
    最近更新 更多