JavaScript 用于在Illustrator中从同一文件夹内重新链接丢失的PDF链接。

huangapple go评论81阅读模式
英文:

Javascript to relink missing link from pdf within same folder within Illustrator

问题

我正在尝试找出一个脚本来重新链接Illustrator中的链接的PDF。基本上,我的文件将在Illustrator中链接来自PDF的两个页面。然后,文件将导出从每个页面的特定部分制作的艺术板的图像。我将重复这个操作250次,所以如果我能自动化这个过程会很棒。

每个images.ai文件将位于单独的文件夹中,以及我想要替换链接的PDF的文件。有什么建议吗?

谢谢!

英文:

I am trying to figure out a script to relink a linked pdf in Illustrator. Basically my file will have two linked pages from a pdf in illustrator. The file will then export images made from artboards from specific sections in each page. I will be repeating this 250 times so, it would be awesome if I could automate it.

Each images.ai file will be in separate folders, along with the pdf I would like to replace the linked pdf with. Any ideas?

Thank you!

答案1

得分: 1

不过,尽管Illustrator不能通过脚本处理多页PDF,但这个简单的解决方案在我的测试文件上仍然有效:

d:\test
├───folder1
│       ├───artwork.ai
│       └───folder1.pdf
├───folder2
│       ├───artwork.ai
│       └───folder2.pdf
└───folder3
        ├───artwork.ai
        └───folder3.pdf

它遍历了文件夹 folder1folder2folder3,打开文件 artwork.ai,并分别使用 folder1.pdffolder2.pdffolder3.pdf 更新了链接。

var main_folder = Folder('d:/test');
var dirs = main_folder.getFiles();

for (var i=0; i<dirs.length; i++) {
    var dir = dirs[i];
    if (dir instanceof Folder) update_links(dir);
}

function update_links(dir) {
    var ai_file = File(dir.fullName + '/artwork.ai');
    var doc = app.open(ai_file);
    var pdfs = doc.placedItems;
    var new_pdf = File(dir.fullName + '/' + dir.name + '.pdf');
    for (var i=0; i<pdfs.length; i++) pdfs[i].relink(new_pdf);
    // doc.save();
    // doc.close();
}

令人惊讶的是,它保持了链接的原始PDF页面不变。试一试。

英文:

Nevertheless, even though Illustrator doesn't handle multi-page pdfs via script this simply solution works somehow fine on my test files:

d:\test
│
├───folder1
│       ├───artwork.ai
│       └───folder1.pdf
│
├───folder2
│       ├───artwork.ai
│       └───folder2.pdf
│
└───folder3
        ├───artwork.ai
        └───folder3.pdf

It iterates through the folders folder1, folder2, folder3, opens the files artwork.ai and updates the links with folder1.pdf, folder2.pdf and folder3.pdf respectively.

var main_folder = Folder(&#39;d:/test&#39;);
var dirs = main_folder.getFiles();

for (var i=0; i&lt;dirs.length; i++) {
    var dir = dirs[i];
    if (dir instanceof Folder) update_links(dir);
}

function update_links(dir) {
    var ai_file = File(dir.fullName + &#39;/artwork.ai&#39;);
    var doc = app.open(ai_file);
    var pdfs = doc.placedItems;
    var new_pdf = File(dir.fullName + &#39;/&#39; + dir.name + &#39;.pdf&#39;);
    for (var i=0; i&lt;pdfs.length; i++) pdfs[i].relink(new_pdf);
    // doc.save();
    // doc.close();
}

Surprisingly it keeps intact original pages of the linked pdfs. Try it.

huangapple
  • 本文由 发表于 2023年4月7日 05:06:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75953792.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定