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

Set page Label without numbering style

Guest
Feb 06, 2019 Feb 06, 2019

Is it possible to apply a page label without numbering style like we can using style "none" with page numbering in Acrobat?

var labels = "4, 9, 13";

var labelsplit = labels.split(", ");

if (labelsplit.length == this.numPages) {

    for (var i=0; i<this.numPages; i++) {

            this.setPageLabels(i, ["D", "", labelsplit]);

            //this.setPageLabels(i, ["r", "", labelsplit]);

            //this.setPageLabels(i, [ "A", "C4-Lot", 4])

    }

}

My problem is if my labels contain something else than integer...

For a label like "C4-LotD" I would have to evaluate if the last letter is upper case and then "D" is the fourth letter of alphabetical order to come out with:

this.setPageLabels(i, [ "A", "C4-Lot", 4])

Label not ending by alphanumeric character will be a problem. Maybe another way to label pages?

TOPICS
Acrobat SDK and JavaScript , Windows
841
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 ,
Feb 06, 2019 Feb 06, 2019

Hi,

I don't know if pages labels can be created as you want but working out which number a letter is, is pretty trivial, you could just use.

var pageLabel = "C4-LotD";

// make string uppercase, get last char

var charAsNumber = pageLabel.toUpperCase().charCodeAt((pageLabel.length - 1));

// subtract 64 as that is the start ( well 1 less than an A in ASCII )

charAsNumber -= 64;

this would set the string as a number, no matter if it was uppercase or lowercase, you would get the same number ( I am making the assumption that is what you want)

Caveat: wont work with extended chars.

Regards

Malcolm

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
Guest
Feb 07, 2019 Feb 07, 2019

Thanks, I did'nt know that method. My idea for resolving the char number was to create an array A-Z then do a find to retreive the index number. Still don't know how resolving Label not ending by alphanumeric character...

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 ,
Feb 07, 2019 Feb 07, 2019

Hi,

Are the page label endings predictable, i.e. they are a known set of characters that are allowed or are all characters allowed?

Regards

Malcolm

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
Guest
Feb 12, 2019 Feb 12, 2019
LATEST

After research chance are that labels will end by alphanumerical characters. The only way I found to get a label otherwise is to use Acrobat and put numbering style to "none". This way suggest to label each page one by one which should be rare.

For now i will deal with non-alphanumerical character by adding a "1" and the end. So I will use:

var labels = "I,II,1,2,A,B,@_!";

labelsplit = labels.split(",");

var pageLabel = "";

var prefix = "";

var nStart = 1

if (labelsplit.length == this.numPages) {

    for (var i=0; i<this.numPages; i++) {

            pageLabel = labelsplit;

            mDecimal = pageLabel.match(/\d+$/);

        if (mDecimal) {

            nStart = mDecimal[0];

            prefix = pageLabel.slice(0, mDecimal[0].length*-1);

            this.setPageLabels(i, ["D", prefix, nStart]);

        }

        else{

            prefix = pageLabel.slice(0, -1);

            charAsNumber = pageLabel.charCodeAt((pageLabel.length - 1));

            if (charAsNumber > 64 && charAsNumber < 91) {

                 //is uppercase letter

                this.setPageLabels(i, [ "A", prefix, charAsNumber -= 64])

            }

            else if (charAsNumber > 96 && charAsNumber < 123) {

            //is lowercase letter

                this.setPageLabels(i, [ "a", prefix, charAsNumber -= 96])

            }

            else{

                //dealing with non-alphanumeric ending, for now add at numbering "1"

                this.setPageLabels(i, [ "D", pageLabel, 1])

            }

        }

    }

}

Is there a way to label a page without numbering style?

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