Forum How do I...?

Is it possible to skip numbering a named page group?

pbreslin
We create both student and instructor workbooks from the same XML. We often insert instructor notes on separate pages inside the instructor workbook that are not in the student workbook. We want the note pages to not be numbered, so that the other pages that are numbered match in both instructor workbook and the student workbook. If the instructor notes are only one page long, I can use counter-increment: page -1 to reset the page numbering, but if the note is more than one page long, I don't know how prevent the page count from going up.

For example, in the student book, we might have page 1, 2, 3, but in the instructor book we might have page 1, unnumbered note page, 2, 3. Is it possible to do this?

Thanks,

Pat
mikeday
I don't think this is possible yet without knowing the number of pages in advance, or running Prince twice.
hallvord
It would be quite nice to support the CSS counter-increment property inside @page blocks. This would be easy if we could write something like the attached code.. For the wishlist :) No idea if it's hard or not, code-wise.

Announcement: repos for tests/utils

  1. page-numbering-exclude-certain-pages-001.htm5.2 kB
hallvord
It might be possible to solve this issue using a small variation of the JavaScript hack I posted here:
http://www.princexml.com/forum/topic/2568/marks-crop-cross-over-the-top#17433
You would still have to run Prince twice though, just to copy some information from the output of the first run and insert it into the script. Here's some JavaScript that would create two distinct, serial sets of page numbers depending on CSS selectors matching content inside a given page. Be sure to edit the suppressPageNumForSelectors list. The output you'll need to paste will look slightly different, otherwise the steps in the post I link to above apply.

(function(){
    // This list can be customized by hand or auto-generated
    var pages = {};
    // If you wish to auto-generate the list, add
    // CSS selectors matching elements that should
    // "suppress" page numbers here and run Prince once,
    // then paste the output above:
    var suppressPageNumForSelectors = ['div.notes'];

    var numNotePagesSofar = 0;
    Prince.addScriptFunc("pageNumOrNot", function(num) {
        if(num in pages){
            numNotePagesSofar = pages[num];
            return 'Notes p ' + numNotePagesSofar;
        }
        num = parseInt(num, 10);
        return '' + (num - numNotePagesSofar);
    });

    // Below is code for auto-generating the list of pages that page numbers
    // should be omitted for
    Prince.trackBoxes = true;
    Prince.addEventListener("complete", function() {
        var pages = {};
        var numSeenNotePages = 0;
        var lastSeenNotePage = null;
        for(var i = 0; i < suppressPageNumForSelectors.length; i++) {
            var elms = document.querySelectorAll(suppressPageNumForSelectors[i]);
            for(var j = 0; j < elms.length; j++) {
                var boxes = elms[j].getPrinceBoxes();
                for (var k = 0; k < boxes.length; ++k) {
                    if(boxes[k].pageNum !== lastSeenNotePage) {
                        numSeenNotePages++;
                        lastSeenNotePage = pages[boxes[k].pageNum];
                    }
                    pages[boxes[k].pageNum] = numSeenNotePages;
                }
            }
        }
        console.log('// Paste this code into the script to suppress listed page numbers:');
        console.log('var pages = ' + JSON.stringify(pages));
    });
})();

Announcement: repos for tests/utils

hallvord
Here's an example of a page using this script:
https://gist.github.com/hallvors/9d03be4d87aac50590ac32a94d91785f
Hope this helps, please let me know if this is useful :)

Announcement: repos for tests/utils