Mathematical syntax...

Hi everybody, I need to figure out how to use the right syntax to do that:

tell application "Adobe Acrobat Pro"
		open theFile
		set PageCount to (count of every page)
		set PageCountINDD to ((count of every page) / 4)

I need to the answer of (PageCoundINDD) to increase to the next integer who’s dividable by 8.

Can somebody help me please?

Maybe this may help :

set PageCountINDD to PageCount div 4
	if PageCountINDD / 8 = PageCountINDD div 8 then exit repeat
	set PageCountINDD to PageCountINDD + 1
end repeat

Yvan KOENIG (VALLAURIS, France) jeudi 6 février 2014 18:15:52

Here is one way of accomplishing your page math problem that assumes the pdf document of interest is open in Acrobat. :slight_smile:

tell application "Adobe Acrobat Pro"
	set PageCount to the number of pages of the active doc
	set PageCountINDD to (PageCount / 4)
end tell


(PageCountNDD + 8) div 8 * 8

Hi. Your intent is unclear. Let’s say you have a 19 page document… Nigel’s approach would give you 24 as a result, which is divisible by 8, but isn’t within your existing page range. If you want to just advance by 8, you could do:

tell application "Adobe Acrobat Pro"
	repeat with whatever from ((count pages) div 4) to count pages by 8

It seems that you read wrongly Nigel code.

With a 19 pages document Nigel’s code returns PageCountNDD = 8

Yvan KOENIG (VALLAURIS, France) jeudi 6 février 2014 19:46:32

Hi Yvan.

My code returns the next multiple of 8 up from whatever PageCountNDD is at that moment.

Sorry I didn’t explain myself well and made a mistake!

It’s the PageCount of my PDF that need to be dividable by 8. So if it’s not, I will add blank pages to reach that number.

not an one-liner, but this solution does not add anything if the number of pages is dividable by 8

set PageCountINDD to numberOfPages() -- pseudo handler for application specific code
set modulo to PageCountINDD mod 8
if modulo is not 0 then
	set PageCountINDD to PageCountINDD + 8 - modulo
end if

PS: I’m using this in Acrobat for a brochure print (dividable by 4) to add empty pages

             repeat while ((count pages of mainDoc) mod 4 is not 0)
                    tell mainDoc to insert pages after (count pages of mainDoc) from emptyPageDoc number of pages 1 starting with 1
                end repeat

It’s what I was trying to point.
Maybe I was not clear enough.

With a document of 19 pages, the initial value of PageCountNDD is 19/4 = 4.75
So your code returns 8.

I was just responding to Marc Anthony who wrote that your code was returning 24.

Here is StephanK 's algorithm as a one liner :

tell PageCountINDD mod 8 to if it is not 0 then set PageCountINDD to PageCountINDD + 8 - it

Yvan KOENIG (VALLAURIS, France) jeudi 6 février 2014 21:22:40

Stefan’s method’s more suitable than mine for the purpose decribed in post #8, since it doesn’t raise numbers which are already multiples of 8. Yvan’s successfully one-lined it, but it can also be done mathematically like this:

PageCountINDD + (8 - PageCountINDD mod 8) mod 8

In Nigel’s code, the variable PageCountNDD was not supposed to be the count of every pages but the result of

(count of every pages pages) / 4

Yvan KOENIG (VALLAURIS, France) vendredi 7 février 2014 11:05:07