Here is the solution. I knew as soon as I asked the question I would find the answer!
First off, the query building code must not run pager_default_initialize
, like so:
$total = $query->countQuery()
->execute()
->fetchField();
$page = pager_find_page();
$query->extend('PagerDefault')
->limit($per)
->range($page * $per, $per);
The pager render array should be created like so:
$content['results']['pager'] = array(
'#pre_render' => array('CUSTOM_PRE_RENDER'),
'#theme' => 'pager',
'#variables' => array(
'total' => $total,
'per' => $per,
),
);
And then run pager_default_initialize
in the custom pre render function:
function _document_library_intialize_pagercustom_pre_render_intialize_pager($_element) {
pager_default_initialize($_element['#variables']['total'], $_element['#variables']['per']);
return $_element;
}
This code will only work to add a single pager to the block and may not work if there is more then one pager on the page.