Beenden
  • Globale Community
    • Sprache:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

Get pageNum of a OCG

Engagiert ,
Oct 09, 2018 Oct 09, 2018

I am trying to identify what page number a certain layer is on. So I am getting all the OCGs then comparing for 2 specific layer names.

"No Color" and "651 Highways"

I am trying to identify what page number these reside on in the document and output it to the console.

Here is my code that I am running from the document level. It works with the exception of this.pageNum which obviously gives me the current page...not the page that the particular layers reside on.

var ocgArray = this.getOCGs();

for (var i = 0; i < ocgArray.length; i++) {

if (ocgArray.name == "No Color") {

console.println("Found " + ocgArray.name + "\nPage number: " + this.pageNum);

}

if (ocgArray.name == "651 (Highways)") {

console.println("Found " + ocgArray.name + "\nPage number: " + this.pageNum);

}

}

On a side note....I will be searching for a pretty long list of layer names.... would this be better to create an array of layer names to search against?

Any help would be much appreciated!

THEMEN
Acrobat SDK und JavaScript , Windows
1.3K
Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines

correct answers 1 richtige Antwort

Community Expert , Oct 09, 2018 Oct 09, 2018

The only relationship between the page number and a particular OCG is the "getOCGs()" function. Sooo, the only way to get the page related to a particular OCG is to use this function.

For example, this code prints out all OCGs on a per page basis.

for(pg=0;pg<this.numPages;pg++)

{

  console.println("Page# " + pg);

  console.println("\tOCGs: " + this.getOCGs(pg).toString());

}

Übersetzen
Community Expert ,
Oct 09, 2018 Oct 09, 2018

You can specify the page as parameter of the method getOCGs.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Engagiert ,
Oct 09, 2018 Oct 09, 2018

Using the nPage parameter?

But I don't know what page the layers will reside on....it will change from document to document.

So sometimes it may exist on page 4 sometimes on 2.... sometimes not at all.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Oct 09, 2018 Oct 09, 2018

Yes, this parameter.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Engagiert ,
Oct 09, 2018 Oct 09, 2018

Ok. I don't understand the syntax that I need to show me what page number the specific OCG is on....

var ocgArray = this.getOCGs(nPage);

for (var i = 0; i < ocgArray.length; i++) {

if (ocgArray.name == "No Color") {

console.println("Found " + ocgArray.name + "\nPage number: " + ocgArray.nPage);

}

if (ocgArray.name == "651 (Highways)") {

console.println("Found " + ocgArray.name + "\nPage number: " + ocgArray.nPage);

}

}

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Oct 09, 2018 Oct 09, 2018

The page number is nPage. A ocg has no property named nPage.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Engagiert ,
Oct 09, 2018 Oct 09, 2018

I see what you are saying. nPage returns the page number for the ocgs....when called getOCGs(nPage)

So can you tell me how to output that page number for the layer into the console?

  1. if (ocgArray.name == "No Color") {
  2. console.println("Found " + ocgArray.name + "\nPage number: " + WHAT GOES HERE TO SHOW "No Color" IS ON PAGE NUMBER ______ );
  3. }
Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Oct 09, 2018 Oct 09, 2018

You can use this:

console.println(nPage);

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Oct 09, 2018 Oct 09, 2018

The only relationship between the page number and a particular OCG is the "getOCGs()" function. Sooo, the only way to get the page related to a particular OCG is to use this function.

For example, this code prints out all OCGs on a per page basis.

for(pg=0;pg<this.numPages;pg++)

{

  console.println("Page# " + pg);

  console.println("\tOCGs: " + this.getOCGs(pg).toString());

}

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

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
LEGENDE ,
Oct 09, 2018 Oct 09, 2018

An OCG is global. It might be referred to on many pages.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Oct 09, 2018 Oct 09, 2018

I'm going to add a little context. First, you can't do directly what you are trying to do though Thom's answer will get you there. An OCG is an Optional Content Group. The OCGs are defined at the document level and sets of content on one or more pages can be set to belong to one or more groups. The nPage parameter in this.getOCGs(nPage) will return an array of OCG objects for the content on that page that is marked to belong to any group. Therefore, the only way to determine which pages have content hat belongs to a particular group is to loop through all the pages. If you know that a particular OCG is referenced by only one page, this isn't a big deal but as you state in your question, you've got a lot of layers and I'm guessing long files.

I suggest you write your code to build an array of arrays where each element of the outer array corresponds to a page number and each element of that array is an array of OCG names that are on that particular page. Then process the array for whatever actions you need to take rather than what you are doing now. It'll be a lot faster. 

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Engagiert ,
Oct 10, 2018 Oct 10, 2018
AKTUELL

Thank you all for the help and guidance. I marked Thom's answer as correct since it will point me to making the connection I need. Thank you for the explanation and feedback Joel Geraci​... That was very helpful as well!

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines