英文:
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
它遍历了文件夹 folder1
,folder2
,folder3
,打开文件 artwork.ai
,并分别使用 folder1.pdf
,folder2.pdf
和 folder3.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('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();
}
Surprisingly it keeps intact original pages of the linked pdfs. Try it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论