使用JavaScript在Acrobat中导入图像(在文档级别上首选) [英] Import image in Acrobat using JavaScript (preferred on document-level)

查看:293
本文介绍了使用JavaScript在Acrobat中导入图像(在文档级别上首选)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将在Adobe Acrobat中使用JavaScript实现动态图例。

I am going to implement a dynamic legend using JavaScript in Adobe Acrobat.

文档包含很多层。每个图层都有自己的图例。最初的想法是实施图例,以便在对话框中包含可见图层的图像。

The document contains a lot of layers. Every layer has an own legend. The origin idea is to implement the legend so, that it contains the images in a dialog box for the visible layers.

在文档级,我只能通过将状态设置为false或true(this.getOCGs()[i] .state = false;)来隐藏/显示图层。

I can only hide/show the layers by setting state to false or true (this.getOCGs()[i].state = false;) on document-level.

问题1:能否以某种方式从图层中提取数据以建立图例?我认为没有,因为我们在图层上仅具有以下功能:getIntent(),setIntent()和setAction()。对?因此,我决定进行排列,以便将每个图层所需的所有图标保存在具有相应名称的文件夹中。 JavaScript应该导入图标,然后用可见的图层图标构建一个对话框窗口,并放置文本(此图标的说明)。

Question 1: Can I extract data from layer somehow for legend establishing? I think no, as we only have these function on layers: getIntent(), setIntent() and setAction(). Right? Therefore I decided to arrange it so, that all needed icons for every layer are saved in a folder with corresponding names. JavaScript should import the icons and I build the a dialog window with icons of visible Layers and place a text(description for this icon).

我尝试了此处介绍的图像导入的所有可能性: http://pubhelper.blogspot.com.au/2012/07/astuces-toolbar-icons-et-javascript.html 。我只有一种方法(将图标转换为十六进制字符串)。这种方法不好,因为要用其他工具从图像中创建十六进制字符串并将其放入javascript代码中是一项繁重的工作。
不幸的是,我无法使用其他方法导入图像:(。由于Adobe的安全设置在版本7或更高版本左右发生了更改,因此无法使用app.newDoc,app.openDoc甚至app.getPath之类的功能在文档级别,我决定使用如下所示的受信任函数在文件夹级别实现导入:

I tried all possibilities of image import described here: http://pubhelper.blogspot.com.au/2012/07/astuces-toolbar-icons-et-javascript.html. I got only one way (Convert the icons as hexadecimal strings). This way isn't good, as it is too much work to create with an other tool a hexadecimal string from a images and place it into a javascript code. Unfortunately, I cannot import image using other methods:(. Since the security settings in Adobe are changed after version 7 or so, it is not possible to use functions like app.newDoc, app.openDoc, even app.getPath On document-level. I decided to implement the import on a folder level using trusted functions like this:

Variant 1:

Variant 1:

var importImg = app.trustedFunction(function() {
app.beginPriv();
var myDoc = app.newDoc({
    nWidth: 20,
    nHeight: 20
});

var img = myDoc.importIcon("icon", "/icon.png", 0);
app.endPriv();
return img;   });  
var oIcon = importImg();

首选项-> JavaScript-> JavaScript安全性中的设置被禁用(启用菜单项JS执行特权,启用全局对象安全性策略)
NotAllowedError:安全性设置阻止访问此属性或方法。
App.newDoc:109:文件夹级:User:acrobat.js

The settings in Preferences->JavaScript-> JavaScript Security are disabled (Enable menu item JS execution privileges, enable global object security policy) NotAllowedError: Security settings prevent access to this property or method. App.newDoc:109:Folder-Level:User:acrobat.js

变量2:

var importImg = app.trustedFunction(function() {
var appPath = var phPath = app.getPath({
    cCategory: "user",
    cFolder: "javascript"
});

try {

    app.beginPriv();
    var doc = app.openDoc({
        cPath: phPath + "/icon.png",
        bHidden: true
    });
     app.endPriv();
} catch (e) {
    console.println("Could not open icon file: " + e);
    return;
}

    var oIcon = util.iconStreamFromIcon(doc.getIcon("icon"));
return oIcon;});
var oIcon = importImg();

无法打开图标文件:NotAllowedError:安全设置阻止访问此属性或方法。

Could not open icon file: NotAllowedError: Security settings prevent access to this property or method.

至少它允许执行所有这些功能,例如app.newDoc,但是在第二个变体中,它指出内容范围错误。也许这里是从图像创建的PDF错误的?

At least it allows the execution of all these functions like app.newDoc, but in the second variant it says, wrong range of content or so. Maybe is here the pdf from an image created false? I just took the image and printed it into a pdf.

我尝试了.jpg,.png和.pdf的所有这些可能性。

I tried all these possibilities with .jpg, .png, .pdf. with different sizes(big images and 20x20), It doesn't work.

有人用不同的尺寸(大尺寸的图像和20x20)无法正常工作。我花了很多时间尝试不同的可能性。实际上,在文档级别实现上述主要目标会更好,这可能吗?

Could somebody help me, as I spent a lot of time with trying different possibilities. It would be actually better to implement the main goal described above on document level, is it possible?

谢谢您,亲切的问候,亚历克斯

Thank you and kind regards, Alex

推荐答案

您是否已在Acrobat中完全激活了控制台?如果不是,请这样做并查找您收到的错误消息。

Do you have the Console fully activated in Acrobat? If not, do so and look for error messages you get.

第一个变体不起作用,因为未定义myDoc(除非您在调用

The first variant does not work, because myDoc is not defined (unless you have done that before you call the importImg function).

如果要将图像导入到新创建的文件中,则必须引用使用newDoc()创建的文档对象。实际上,这将链接到myDoc,例如

If you want to import the image into the newly created file, you will have to make a reference to the Document Object you create with newDoc(). Actually, that would make the link to myDoc, as in

var myDoc = app.newDoc(1,1)

(您确定要创建尺寸为1x1 pt的文档吗?)

(are you sure you want to create a document measuring 1x1 pt?)

第一个变体的下一个问题是Acrobat中的一个错误,该错误会在保存文档时丢弃浮动的图标对象。您必须将图标对象附加到字段以保留它;此字段可以隐藏,甚至可以隐藏在文档的隐藏模板页面上。

The next issue with the first variant is a bug in Acrobat, which discards "floating" Icon Objects when saving the document; you'd have to attach the Icon Object to a field to keep it; this field can be hidden, or even on a hidden Template page in the document.

这篇关于使用JavaScript在Acrobat中导入图像(在文档级别上首选)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆