首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Ai文件中标记/标记对象并将其保存为pdf格式?

如何在Ai文件中标记/标记对象并将其保存为pdf格式?
EN

Stack Overflow用户
提问于 2021-10-20 07:45:01
回答 1查看 64关注 0票数 0

我有一个AI文件,我用AITagSuite标记了一些艺术

(标签实际上作为字符串条目存储在art对象字典中)

我想在不丢失标签的情况下将ai文件转换为pdf。当我将ai文件转换为pdf时,我无法访问标记。

你知道如何标记/标记Ai文件中的对象并将其保存在pdf中吗?

我也想过使用一些其他的库,可以获得AI文件作为输入,并将其转换为带有标签的pdf,有什么想法吗?

感谢您的支持

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-29 19:59:31

下面是一个示例,如何从Illustrator中将标记的pathItems的属性保存到一个类似JSON的文件中,并从该文件中读回它们:

代码语言:javascript
复制
var items = app.activeDocument.pathItems;

// add tags to a couple of pathItems
var tag = items[0].tags.add();
tag.name = 'tag1';
tag.value = '123';

var tag = items[1].tags.add();
tag.name = 'tag2';
tag.value = '456';

// put all tagged pathItems into the array 'tagged_items'
// and add to each of the items its properties:
// 'tags':            Array of object: [{name:value},{name:value},...]
// 'color':           Array of Numbers and Sting, for example: [10,0,25,15,'CMYKColor'] or [56.9845,'GrayColor']
// 'geometricBounds': Array of Numbers: [y1,x1,y2,x2]

var tagged_items = [];

var i = items.length;
while (i--) {
    var item = items[i];
    if (item.tags.length == 0) continue; // skip if the pathItem has no tags

    var tags = []; // make an array of tags
    for (var t=0; t<item.tags.length; t++) {
        var key = item.tags[t].name;
        var value = item.tags[t].value;
        var tag = {};
        tag[key] = value;
        tags.push(tag);
    }

    var fillColor = []; // make an array of fillColor properties
    for (var c in item.fillColor) fillColor.push(item.fillColor[c]);

    // put the item into the array of tagged items
    tagged_items.push  (
        {
            'tags': tags,
            'fillColor': fillColor,
            'geometricBounds': item.geometricBounds,
        }
    );  
}

// save the array in JSON-like file
var file = File('d:/tagged_items.json');
file.open('w');
file.write(tagged_items.toSource());
file.close();

// read the array from the file and show the properties
var file = File('d:/tagged_items.json');
var tagged_items = $.evalFile(file);
for (var i in tagged_items) alert('pahtItem ' + i + ':\n' + props(tagged_items[i]));


// ----------------------------------------------------------------------------
// returns a string with all properties of a given object
function props(obj) { 
    msg = '';
    for (var p in obj) msg += p + ': ' + obj[p].toSource() + '\n';
    return msg;
}

如果您能够使用Acrobat读取类似JSON的文件,并将其中的属性与PDF文件中对象的属性进行比较,您就有机会完成您的任务。

这只是一个例子。它不能很好地处理组、专色等。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69642124

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档