     '
          
   end: ->
-    @page.end()
-    
+    @flushPages()
     @_info = @ref()
     for key, val of @info
       if typeof val is 'string'

    # Whether streams should be compressed
    @compress = @options.compress ? yes
    
    # The PDF object store
    @_offsets = []
    @_waiting = 0

    @transform 1, 0, 0, -1, 0, @page.height
    
    return this

  bufferedPageRange: -> { start: @_pageBufferStart, count: @_pageBuffer.length }

  switchToPage: (n) ->
    unless page = @_pageBuffer[n-@_pageBufferStart]
      throw new Error("switchToPage(#{n}) out of bounds, current buffer covers pages #{@_pageBufferStart} to #{@_pageBufferStart + @_pageBuffer.length - 1}")
    @page = page

  flushPages: ->
    # this local variable exists so we're future-proof against
    # reentrant calls to flushPages.
    pages = @_pageBuffer
    @_pageBuffer = []
    @_pageBufferStart += pages.length
    for page in pages
      page.end()
    null

  ref: (data) ->
    ref = new PDFReference(this, @_offsets.length + 1, data)
    @_offsets.push null # placeholder for this object's offset once it is finalized
