Skip to main content
Known Participant
May 4, 2020
Answered

How to get page count in C++

  • May 4, 2020
  • 4 replies
  • 1959 views

Hi Professionals,

I don'tknow how to add the page count values in C++ . Please guide me ASAP

This topic has been closed for replies.
Correct answer Chinnadk

Try this,

 

IDocument* doc = Utils<ILayoutUIUtils>()->GetFrontDocument();

InterfacePtr<IPageList> pagelist(doc, IID_IPAGELIST);
int32 count = pagelist->GetPageCount();

4 replies

Alo Lohrii
Community Manager
Community Manager
June 11, 2020

duplicate thread/spam, locked

Community Expert
May 8, 2020

I doubt the code you pasted is the one that you are running in your plugin, looking at it i suspect it will even compile. You can't join a string value with an integer as you have done inside CAlert. See screenshot below

 

 

 

 

 

 

 

Also your explanation is a bit confusing, you say you get 2 as the result but null as well. Do both these scenarios happen with the same document randomly? If not then what different do you do when the result is null? Are you able to debug your code?

 

Please answer every question i have asked for helping us help you, giving cryptic one line answers with a different code everytime which apparently is wrong and hence not working in the first place just wastes time all around.

 

-Manan

Known Participant
May 8, 2020

Hi,

I have used this code in my plugin by that time it works and provide the null value and I have used two different document to display the page count value. but it display the null value. I have an doubt that how can I check the page count values using alertbox

 

Regards,

Rajendran 

Rajendran
Community Expert
May 6, 2020

Hi together,

I'm no SDK developer, just know my way arround in the ExtendScript DOM.

From that I know that the value of the page length can also obtained by a preference of the document:

documentPreferences.pagesPerDocument

 

Important note: pagesPerDocument is read/write

So it can be used at any time, when creating a document or even after a document is created, to change the number of document pages:

 

app.documents.add
(
{ documentPreferences : { pagesPerDocument : 10 } }
);

 

app.documents[0].documentPreferences.pagesPerDocument = 5 ;

 

And it's a very straight forward way to get the number of pages without asking the list of document pages:

 

var numberOfPagesInDoc = app.documents[0].documentPreferences.pagesPerDocument;

 

It should be possible to access the equivalent of pagesPerDocument with the SDK as well…

 

Regards,
Uwe Laubender

( ACP )

Community Expert
May 6, 2020

Hi Uwe,

 

You are right, that would correspond to GetNumPagesPref method in IPageSetupPrefs interface on the kDocWorkspaceBoss boss class. The issue is not about finding a new way to do it, since the code shared already seems to work fine. I have tested the code and it seems to be working fine

 

-Manan

Known Participant
May 8, 2020

I have run the code for the first time it provide the correct value but while running the code it provides an null value is this used method is correct or not. If it goes wrong please suggest me with the solution. But it gives the exact output as "2"

 

IDocument* doc = Utils<ILayoutUIUtils>()->GetFrontDocument();
if(doc)
{
InterfacePtr<IPageList> pagelist(doc, IID_IPAGELIST);
int32 count = pagelist->GetPageCount();
CAlert::WarningAlert("Values:"+count);

}

Now output recieved for me is attached for the reference

 

 

Regards,

Rajendran

Rajendran
Chinnadk
ChinnadkCorrect answer
Brainiac
May 4, 2020

Try this,

 

IDocument* doc = Utils<ILayoutUIUtils>()->GetFrontDocument();

InterfacePtr<IPageList> pagelist(doc, IID_IPAGELIST);
int32 count = pagelist->GetPageCount();

Inspiring
May 6, 2020

Hi,

I have used this following code and it compiles without any error but it doesn't give any value after the compilation process gets completed.

 

-Monisha

-Monisha
Community Expert
May 6, 2020

The code given works perfectly for me, what does "doesn't give any value after the compilation process gets completed" mean?

 

-Manan