These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

automate page resizing using app.execDialog

Suprem0
Registered: Feb 12 2008
Posts: 13

Hi,

I'm new to javascripting, and I have just read the dialog objects. I tried to use a sample script to come up with my own. Here it is:

var dialog2 =
{
initialize: function(dialog) {
dialog.load({
"bled": "0",
"pgwd": "0",
"pght": "0",
"rd01": true,
"rd02": false,
"rd03": false
}),
this.hasPet = false;
dialog.enable({
"bled" : this.hasPet
});
},
commit: function(dialog)
{
var aaa = dialog.store()["pgwd"];
var bbb = dialog.store()["pght"];
var ccc = dialog.store()["bled"];
var eee = dialog.store()["rd01"];
var fff = dialog.store()["rd02"];
var ggg = dialog.store()["rd03"];
if (eee == true) {
var x = 2.83464762
}
else {
if (fff == true) {
var x = 72
}
else {
if (ggg == true) {
var x = 1
}
}
}
for (var i = 0; i < numPages; i++) {
var ddd = this.getPageBox("Media", i);
var a = ddd[0]
var b = ddd[1]
var c = ddd[2]
var d = ddd[3]
console.println(a+" "+b+" "+c+" "+d)
}
},
ok: function(dialog) {
console.println("Ok!")
},
ckbx: function (dialog) {
this.hasPet = !this.hasPet;
dialog.enable({
"bled" : this.hasPet,
});
},
cancel: function(dialog) {
console.println("Cancel!");
},
description:
{
name: "Resize Page Box",
elements:
[
{
type: "view",
align_children: "align_left",
elements:
[
{
type: "static_text",
name: "Required Data",
bold: true,
font: "dialog",
char_width: 30,
height: 20
},
{
type: "view",
align_children: "align_row",
elements:
[
{
type: "static_text",
name: "Page Width: ",
},
{
type: "edit_text",
item_id: "pgwd",
group_id: "pgbx",
name: "Page Width",
char_width: 5,
height: 20
},
{
type: "static_text",
name: "Page Height: ",
},
{
type: "edit_text",
item_id: "pght",
group_id: "pgbx",
char_width: 5,
height: 20
}
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
type: "check_box",
item_id: "ckbx",
name: "Bleed"
},
{
type: "edit_text",
item_id: "bled",
char_width: 5,
height: 20
}
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
type: "static_text",
name: "Units of measurements: "
},
{
type: "radio",
item_id: "rd01",
group_id: "rado",
name: "millimeter"
},
{
type: "radio",
item_id: "rd02",
group_id: "rado",
name: "inch",
},
{
type: "radio",
item_id: "rd03",
group_id: "rado",
name: "point",
}
]
},
{
type: "ok_cancel",
ok_name: "Ok",
cancel_name: "Cancel",
}
]
},
]
}
};
var retn = app.execDialog(dialog2)

But when I press the ctrl enter, nothing happens. When I changed the code:

var ddd = this.getPageBox("Media", i);
var a = ddd[0]
var b = ddd[1]
var c = ddd[2]
var d = ddd[3]
console.println(a+" "+b+" "+c+" "+d)

to:

console.println(x)

I get an output.

Can someone please explain what I missed and what do I need to add to this code for it to work. Thanks! and more power!!!

Suprem0
Registered: Feb 12 2008
Posts: 13
Please, if someone know the answer on this, please post a reply. Thanks!
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The problem is that you posted too much code and didn't explain what you are trying to achieve and what exactly goes wrong. Be more specific in your description and you'll have a better chance of getting a meaningful answer.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Suprem0
Registered: Feb 12 2008
Posts: 13
Sorry about that. Ok, I'm just experimenting on how to use the dialog objects, especially the initialize and commit function. In this sample, I'm trying to create a program that will resize a page based on the input data. Here are the definition of the following variables:

bled = for bleed allowances
pgwd = page width of the trim box
pght = page height of the trim box
rd01 - rd02 = unit of measurements used.

I'm just confused. When I used a simple command in the commit: function like console.println, the created script produces an output. But if I used getPageBox, nothing happened. Is getPageBox not allowed inside the commit: function? Thanks in advance!
try67
Expert
Registered: Oct 30 2008
Posts: 2398
That's better.

I think the problem is related to your usage of the "this" object. Inside the dialog definition "this" does not point to the open document but to the dialog itself. Therefore this.getPageBox has no meaning.

I would try saving a reference to the open document in a variable that is defined outside of the dialog.
Then you could access that variable from within your dialog and use getPageBox on it.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Suprem0
Registered: Feb 12 2008
Posts: 13
Thanks so much try67. I'll try that one. Many thanks!!!