Copy link to clipboard
Copied
The company I work at has a lot of print orders containings books and magazines.
For now we use a website, but we would like to use a pdf calculating the spine thickness.
Now is coding not one of my best skills, but coding in pdf files is completely new for me.
The result should be that a client can choose a paper weight from a dropdown menu, a amount of pages and a paper volume. Say if the volume would be "matt" and the pagecount is 128 and the weight would be 130, the sum would be:
Spine = (9*130*128)/20000
Every volume has a own parameter. so does softcover and hardcover. Every var is linked to a form field in the said PDF. Now the problem starts when I want to get the value of the dropdown menu using getfield. How does the script know the value of the selected value in the dropdown menu.
If it is not clear enough I will give more information.
Thanks in advance.
var Volume = this.getField("Volume");
var Weight = this.getField("Weight");
var Count = this.getField("Count");
var Cover = this.getField("Cover");
var Spine;
/////Paper Volume
if (Volume.value == "Matt")
{
return "9";
}
if (Volume.value == "Gloss")
{
return "8";
}
if (Volume.value == "Silk")
{
return "9";
}
/////Cover kiezen
if (Cover.value == "Hardcover")
{
return "6";
}
if (Cover.value == "Softcover")
{
return "1";
}
Spine = Volume*Weight*Count/20000;
Copy link to clipboard
Copied
Why is that a problem? You access it using getField and the value property, just like any other field.
PS. You can only use the return command in a function, and it doesn't seem you've created a function here, so that won't work. Instead, just apply it to a variable and then use that variable in your calculation. However, you should drop the double-quotes around the values, as that converts them into strings and will make working with them later on more problematic.
Copy link to clipboard
Copied
I strongly advice your company to invest in a proper ordering system for your clients, written and maintained professionally. These are large value transactions, have you evaluated the effect on your business if, say, 10% of orders are lost forever - a conservative guess for a PDF form.
Copy link to clipboard
Copied
Where do you use "Cover" in your script calculation?
You set it to "Spine" var but you didn't use it to set field value(at least not that I see).
EDIT:
If you want to show result in text field you can try something like this as custom calculation script of text field:
var Volume = this.getField("Volume").valueAsString;
var Weight = this.getField("Weight").value;
var Count = this.getField("Count").value;
var Cover = this.getField("Cover").valueAsString;
var v = 0;
var c = 0;
/////Paper Volume
if(Volume == "Matt")v=9;
else if (Volume == "Gloss")v=8;
else if (Volume == "Silk")v=9;
/////Cover kiezen
if(Cover == "Hardcover")c=6;
else if(Cover == "Softcover")c=1;
if(v == 0 || c == 0) event.value = "";
else
event.value = v*Weight*Count/20000;
Just add "c" to calculation because I wasn't sure where you want to add "Cover" to calculation.