Forum How do I...?

counter(pages) to word presentation

BadSanta
Hello everyone!

I generate pdf by php. I need to write something like that:
.pageCountAll
    {
        content: counter(pages);
    }

This document is on <span class=pageCountAll></span>[b] (here must be word) [/b]pages.

I've function php that can do this, but how I can get this value in PHP?

And another question... How I can do?:
content: counter(pages)-1;


I think that I can also try to use javascript... :)
mikeday
So you need to get the number of pages in the generated PDF back in the PHP? You can do this, but it's a bit tricky, and yes you will need to use a bit of JavaScript. :)
BadSanta
I tried this:
<style>
.pageCount
    {
        content: counter(pages);
    }
</style>
<script type="text/javascript">
function numToText(pages) { return 'number :) '; }
function init() {
   mySpan = document.getElementById('countAll');
   pages = mySpan .innerHTML - 1;
    mySpan.innerHTML = pages + " " + numToText(pages);
}
</script>
<body onload=init();>
...

But as a result I see that the value is that content: counter(pages); set. This means that javascript work before this css works. Am I right? How to solve this problem?

I thought that my javascript works when DOM is loaded and prince css generate pre-html with counter and etc. :)
mikeday
Use a script function! Then you can pass the counter value to a JavaScript function, that will be called when Prince evaluates the generated content. Whatever it returns will be used as the value.
BadSanta
Thx! :)