Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
5

Issue rotating radiobutton

New Here ,
May 10, 2024 May 10, 2024

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)
}

 

TOPICS
JavaScript , PDF forms
457
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
May 10, 2024 May 10, 2024
LATEST

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);
}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2024 May 10, 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2024 May 10, 2024
LATEST

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);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines