Articles in this section
Category / Section

How to set text direction for text boxes using BoldSign API?

Published:
5 mins read

BoldSign API allows you to set text directions such as RTL (Right-to-Left) or LTR (Left-to-Right) for text boxes.

Setting the textDirection property as RTL for textbox form fields is essential when dealing with languages that follow RTL script orientation. By default, the textDirection property is set to LTR.

RTL and LTR differences

  • Right-to-Left (RTL): Text flows from right to left, standard for languages such as Arabic, Hebrew, Persian, etc.
  • Left-to-Right (LTR): Text flows from left to right, standard for languages such as English, French, Spanish, etc.

Here are example codes you can use to do set text direction for text boxes:

Code snippet

cURL

curl -X 'POST' \
  'https://api.boldsign.com/v1/document/send' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: {your API key}' \
  -H 'Content-Type: multipart/form-data' \
  -F 'Title="Sample Document"' \
  -F 'Signers={
  "name": "hanky",
  "emailAddress": "hankyWhites@gmail.com",
  "signerType": "Signer",
  "signerRole": "Signer",
  "formFields": [
    {
      "id": "TextBox",
      "name": "TextBox",
      "fieldType": "TextBox",
      "pageNumber": 1,
      "bounds": {
        "x": 100,
        "y": 100,
        "width": 125,
        "height": 25
      },
      "isRequired": true,
      "textDirection": "RTL"
    }
  ],
  "locale": "EN"
}' \
  -F 'Files={your file}' \

C#

var apiClient = new ApiClient("https://api.boldsign.com", "{Your API key}");
var documentClient = new DocumentClient(apiClient);

var documentFilePath = new DocumentFilePath
{
    ContentType = "application/pdf",
    FilePath = "{Your File path}"
};

var filesToUpload = new List<IDocumentFile>
{
    documentFilePath,
};

var TextBoxField = new FormField(
  id: "TextBox",
  isRequired: true,
  textDirection: TextDirection.RTL,
  type: FieldType.TextBox,
  pageNumber: 1,
  bounds: new Rectangle(x: 100, y: 100, width: 125, height: 25));

var formFieldCollections = new List<FormField>()
{
    TextBoxField
};

var signer = new DocumentSigner(
    name: "David",
    emailAddress: "david@cubeflakes.com",
    formFields: formFieldCollections,
    locale: Locales.EN);

var documentSigners = new List<DocumentSigner>()
{
    signer
};

var sendForSign = new SendForSign()
{
    DisableEmails = true,
    Signers = documentSigners,
    Files = filesToUpload,
    Title = "Sample Document"
};
var documentCreated = documentClient.SendDocument(sendForSign);
Console.WriteLine(documentCreated.DocumentId);

Python

import boldsign

configuration = boldsign.Configuration(
    api_key = "YOUR_API_KEY"
)

with boldsign.ApiClient(configuration) as api_client:

    document_api = boldsign.DocumentApi(api_client)
    
    send_for_sign = boldsign.SendForSign(
          title="Document SDK API",
          document_title = "SDK Document Test case",
          description="Testing document from SDK integration test case", 
          files=["YOUR_FILE_PATH"],
          signers=[
                boldsign.DocumentSigner(
                      name="Hanky",
                      emailAddress="hankyWhites@cubeflakes.com",
                      signerOrder=1,
                      signerType="Signer",
                      formFields=[
                            boldsign.FormField(
                                  name="TextBox",
                                  fieldType="TextBox",
                                  font="Helvetica",
                                  pageNumber=1,
                                  isRequired=True,
                                  textDirection="RTL",
                                  bounds=boldsign.Rectangle(x=100, y=100, width=125, height=25)
                            )
                    ],
                    privateMessage="This is private message for signer"
                )
            ]
    )
    
    send_document_response = document_api.send_document(send_for_sign)

NodeJS

const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
let data = new FormData();
data.append('Signers', '{\r\n  "name": "hanky",\r\n  "emailAddress": "hankyWhites@gmail.com",\r\n  "signerType": "Signer",\r\n  "signerRole": "Signer",\r\n  "formFields": [\r\n    {\r\n      "id": "TextBox",\r\n      "name": "TextBox",\r\n      "fieldType": "TextBox",\r\n      "pageNumber": 1,\r\n      "bounds": {\r\n        "x": 100,\r\n        "y": 100,\r\n        "width": 125,\r\n        "height": 25\r\n      },\r\n  "textDirection": "RTL",\r\n    "isRequired": true\r\n}\r\n  ],\r\n  "locale": "EN"\r\n}');
data.append('Files', fs.createReadStream('{Your file path}'));
data.append('Title', "Sample Document");

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.boldsign.com/v1/document/send',
  headers: { 
    'accept': 'application/json', 
    'X-API-KEY': '{Your API key}', 
    ...data.getHeaders()
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

In the above example, set the fieldType as TextBox and the textDirection property to one of the supported text directions like RTL and LTR. Upon executing the above code, a document will be generated with the specified text direction value for the textbox form fields.

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Access denied
Access denied