Skip to main content
Participant
May 11, 2024
Answered

Issue rotating radiobutton

  • May 11, 2024
  • 2 replies
  • 423 views

I have a script that inserts 3 radiobuttons on each page of a document.  The buttons get placed properly with the correct styles and attributes, except for the rotation:

 

    rFld.rotation = 90;

 

The first radio button widget in each group gets properly rotated, but not 2 and 3.  I have tried setting the widget property manually using .# to no avail.  

 

Is there something special about the rotation?

function AddPMGFields(page_num)
{
    var i = page_num;
    var rFld = this.addField("Approval"+(i+1), "radiobutton", i, [725, 60, 735, 50]);
    this.addField("Approval"+(i+1), "radiobutton", i, [725, 137, 735, 127]);
    this.addField("Approval"+(i+1), "radiobutton", i, [725, 212, 735, 202]);
    rFld.exportValues = ["Approved", "As Noted", "Resubmit"];
    rFld.style = style.ch;
    rFld.rotation = 90;
    rFld.lineWidth=0;
    rFld.required = true;
    rFld.fillcolor=color.transparent;
    rFld.strokecolor=color.transparent;
    rFld.borderStyle = border.s;
}

try {

    for (var i = 0; i < this.numPages; i++)
       {
           AddPMGFields(i);
       }
} 
catch(e)
{
app.alert("Processing error: "+e)
}

 

This topic has been closed for replies.
Correct answer Nesa Nurani

Try like this:

function AddPMGFields(page_num) {
    var page = page_num;
    var fieldName = "Approval" + (page + 1);
    var coords = [
        [725, 60, 735, 50],
        [725, 137, 735, 127],
        [725, 212, 735, 202]
    ];

    coords.forEach(function(coord, index) {
        this.addField(fieldName, "radiobutton", page, coord);
    }, this);

    var fieldGroup = this.getField(fieldName);
    fieldGroup.exportValues = ["Approved", "As Noted", "Resubmit"];
    fieldGroup.style = style.ch;
    fieldGroup.lineWidth = 0;
    fieldGroup.required = true;
    fieldGroup.fillColor = color.transparent;
    fieldGroup.strokeColor = color.transparent;
    fieldGroup.borderStyle = border.s;

    for (var j = 0; j < coords.length; j++) {
        var widget = this.getField(fieldName + "." + j);
        if (widget !== null) {
            widget.rotation = 90;
        }
    }
}

try {
    for (var i = 0; i < this.numPages; i++) {
        AddPMGFields(i);
    }
} catch (e) {
    app.alert("Processing error: " + e);
}

2 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
May 11, 2024

Try like this:

function AddPMGFields(page_num) {
    var page = page_num;
    var fieldName = "Approval" + (page + 1);
    var coords = [
        [725, 60, 735, 50],
        [725, 137, 735, 127],
        [725, 212, 735, 202]
    ];

    coords.forEach(function(coord, index) {
        this.addField(fieldName, "radiobutton", page, coord);
    }, this);

    var fieldGroup = this.getField(fieldName);
    fieldGroup.exportValues = ["Approved", "As Noted", "Resubmit"];
    fieldGroup.style = style.ch;
    fieldGroup.lineWidth = 0;
    fieldGroup.required = true;
    fieldGroup.fillColor = color.transparent;
    fieldGroup.strokeColor = color.transparent;
    fieldGroup.borderStyle = border.s;

    for (var j = 0; j < coords.length; j++) {
        var widget = this.getField(fieldName + "." + j);
        if (widget !== null) {
            widget.rotation = 90;
        }
    }
}

try {
    for (var i = 0; i < this.numPages; i++) {
        AddPMGFields(i);
    }
} catch (e) {
    app.alert("Processing error: " + e);
}
Thom Parker
Community Expert
Community Expert
May 11, 2024

Rotation, as well as all the apperance properties, is a property of the field widget, not the field proper.  The widget is the apperance of the field on the page. The field itself is a logical construct that holds a value, but has no apperance.

So, to get the widget use the dot notation. 

For example, this code gets the first widget of a field. 

rFld = this.getField("Approval" + (i+1) + ".0"); 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often