Index: zpt/viewer/common_template.zpt
===================================================================
--- zpt/viewer/common_template.zpt	(revision 594)
+++ zpt/viewer/common_template.zpt	(revision 607)
@@ -45,7 +45,7 @@
   <!-- page ruler with previous/next page buttons -->
   <metal:block metal:define-macro="page_ruler"
-    tal:define="
-              prev python:test(pn>1,pn-1,None); next python:test(pn<numPages,pn+1,None);
-              first python:test(pn>1,1,None); last python:test(pn<numPages,numPages,None);
+    tal:define="minPageNo docinfo/minPageNo; maxPageNo docinfo/maxPageNo;
+              prev python:test(pn>minPageNo,pn-1,None); next python:test(pn<maxPageNo,pn+1,None);
+              first python:test(pn>minPageNo,minPageNo,None); last python:test(pn<maxPageNo,maxPageNo,None);
               left python:test(flowLtr,prev,next); right python:test(flowLtr,next,prev);
               leftest python:test(flowLtr,first,last); rightest python:test(flowLtr,last,first);">
@@ -90,6 +90,6 @@
     <form class="autosubmit" tal:attributes="action viewerUrl">
       <input type="hidden" tal:define="params python:here.getParams('start',None)" tal:repeat="param params"
-        tal:attributes="name param; value python:params[param]" /><span class="ruler-main"><a tal:condition="left"
-        tal:attributes="href python:here.getLink('start',left)">&lt;</a> <span tal:condition="not:left">&lt;</span> <select
+        tal:attributes="name param; value python:params[param]" /><span class="ruler-main"><a tal:omit-tag="not:left"
+        tal:attributes="href python:here.getLink('start',left)">&lt;</a> <select
         class="autosubmit" name="start" tal:define="ofs python:test(pageinfo['pageZero'],0,1)">
           <tal:block>
@@ -98,6 +98,6 @@
             <option tal:condition="python:start>pageBatch['last']" selected="selected" value="1">[out of range]</option>
           </tal:block>
-      </select> <input type="submit" value="Go" /> <a tal:condition="right" tal:attributes="href python:here.getLink('start',right)">&gt;</a>
-        <span tal:condition="not:right">&gt;</span></span>
+      </select> <input type="submit" value="Go" /> <a tal:omit-tag="not:right" tal:attributes="href python:here.getLink('start',right)">&gt;</a>
+      </span>
     </form>
   </metal:block>
Index: zpt/viewer/toc_thumbs.zpt
===================================================================
--- zpt/viewer/toc_thumbs.zpt	(revision 594)
+++ zpt/viewer/toc_thumbs.zpt	(revision 607)
@@ -11,4 +11,6 @@
     <div class="tocbody thumbs"
       tal:define="start pageinfo/start;
+                minPageNo docinfo/minPageNo;
+                maxPageNo docinfo/maxPageNo;
                 grpsize pageinfo/groupsize;
                 numgroups pageinfo/numgroups;
@@ -26,5 +28,7 @@
           <tr tal:repeat="row pageBatch/pages">
             <td tal:repeat="thumb row" tal:attributes="class python:here.getStyle(thumb['idx'],pn,'thumb')"><a
-              tal:define="idx thumb/idx" tal:condition="idx" tal:attributes="href python:here.getLink('pn',idx)"> <img
+              tal:define="idx thumb/idx" tal:condition="idx"
+              tal:attributes="href python:here.getLink('pn',idx); class python:test(idx<minPageNo or idx>maxPageNo, 'outside')"><img
+                tal:condition="python:docinfo.get('imageURL',None) or exists('template/text.png')"
                 tal:attributes="src python:test(docinfo.get('imageURL',None),here.getScalerUrl(pn=idx,dw=100,dh=100,docinfo=docinfo),'template/text.png');
                                 alt idx;" /><br />
Index: zpt/viewer/viewer_thumbs.zpt
===================================================================
--- zpt/viewer/viewer_thumbs.zpt	(revision 594)
+++ zpt/viewer/viewer_thumbs.zpt	(revision 607)
@@ -27,9 +27,11 @@
     tal:define="pn pageinfo/pn;
                 start pageinfo/start;
+                minPageNo docinfo/minPageNo;
+                maxPageNo docinfo/maxPageNo;
                 thumbRows python:int(request.get('thumbRows', 10));
                 thumbCols python:int(request.get('thumbCols', 12));
                 thumbSize python:int(request.get('thumbSize', 100));
                 flowLtr python:docinfo.get('pageFlow','ltr')!='rtl';
-                pageBatch python:here.getPageBatch(start=start, rows=thumbRows, cols=thumbCols, pageFlowLtr=flowLtr, maxIdx=numPages);
+                pageBatch python:here.getPageBatch(start=start, rows=thumbRows, cols=thumbCols, pageFlowLtr=flowLtr, minIdx=minPageNo, maxIdx=maxPageNo);
                 pageNumbers docinfo/pageNumbers | nothing;
                 left python:test(flowLtr,pageBatch['prevStart'],pageBatch['nextStart']);
