如何在pdf中添加自己小工具,以下示范添加一个打圈圈功能的插件

新建文本文档.txt

把下面代码复制粘贴到文件中保存并改名qq.js

插件放在安装目录下

设置一下

工具就出现

global.cs = 1; //count 开始号码

global.cs1 = 8; //字体大小

global.cs2 = 10; //圈圈大小

var dialog1 =

{

initialize: function(dialog){

}

, commit: function(dialog)

{

// called when OK pressed

var results = dialog.store();

global.cs = results["fnum"];

global.cs1 = results["tnum"];

global.cs2 = results["qnum"];

}

, description:

{

name: "Personal Data", // Dialog box title

align_children: "align_left", width: 120, height: 200, elements: [

{

type: "cluster", name: "参数", align_children: "align_left",

elements: [

{

type: "view", align_children: "align_row", elements: [

{

type: "static_text", name: "开始号码: "

}

,

{

item_id: "fnum", type: "edit_text", alignment: "align_fill",

width: 80, height: 20

}

]

}

,

{

type: "view", align_children: "align_row", elements: [

{

type: "static_text", name: "字体大小: "

}

,

{

item_id: "tnum", type: "edit_text", alignment: "align_fill",

width: 80, height: 20

}

]

}

,

{

type: "view", align_children: "align_row", elements: [

{

type: "static_text", name: "圈圈大小: "

}

,

{

item_id: "qnum", type: "edit_text", alignment: "align_fill",

width: 80, height: 20

}

]

}

]

}

,

{

alignment: "align_center", type: "ok_cancel", ok_name: "Ok",

cancel_name: "Cancel"

}

]

}

};

var myscipt = "n" + "var Dx=global.cs2;n" +

"var x1=this.mouseX-parseInt(Dx);n" + "var x2=this.mouseX+parseInt(Dx);n"

+ "var y1=this.mouseY-parseInt(Dx);n" +

"var y2=this.mouseY+parseInt(Dx);n" + "var rr=new Array(4);n" +

"rr[0]=x1;n" + "rr[1]=y1;n" + "rr[2]=x2;n" + "rr[3]=y2;n" +

"var annot = this.addAnnot({n" + "page: this.pageNum,n" +

"type: "Circle",n" + "rect: rr,n" + "readonly : true,n" +

"strokeColor :color.red ,n" + "fillColor:color.transparent,n" +

"name: "圆"n" + "});n" +

"var m = (new Matrix2D).fromRotated(this,this.pageNum);n" +

"var mInv = m.invert();n" + "r= mInv.transform(rr);n" +

"r=r.toString();n" + "r = r.split(",");n" +

"var count=parseInt(global.cs++);n" +

"var f = this.addField("qq"+count, "text",this.pageNum,[r[0], r[1], r[2], r[3]] );n" + "f.delay = true;n" + "f.alignment = "center";n" + "f.textSize=parseInt(global.cs1);n" + "f.value=count;n" + "f.readonly = false;n" + "f.borderStyle = border.s;n" + "f.lineWidth = 0;n" + "f.strokeColor = color.transparent;n" + "f.delay = false;n"function addbottononpage()

{

if (this.getField("圈圈") == null)

{

var aRect = this.getPageBox(

{

nPage: this.pageNum

}

); //获取当前页大小

var f = this.addField("圈圈", "button", this.pageNum, aRect);

//增加一个当前页大小一样得按钮

f.delay = true;

f.setAction("MouseDown", myscipt); //设置鼠标按下动作

f.highlight = highlight.n;

f.readonly = false;

f.borderStyle = border.s;

f.lineWidth = 0;

f.strokeColor = color.transparent;

f.delay = false;

}

app.execDialog(dialog1);

}

function removestop()

{

if (this.getField("圈圈") != null)

this.removeField("圈圈");

}

// 加入菜单color.red

app.addMenuItem(

{

cName: "快速打圈圈", cUser: "打圈圈", cParent: "Document", cExec:

"addbottononpage();", cEnable: "event.rc = (event.target != null);",

nPos: 0

}

);

//加入按钮

app.addToolButton(

{

cName: "打圈圈", cLabel: "打圈圈", cEnable: "event.rc = (app.doc != null);",

cExec: "addbottononpage();"

}

);

app.addToolButton(

{

cName: "STOP", cLabel: "STOP", cEnable: "event.rc = (app.doc != null);",

cExec: "removestop();"

}

);

// end of script