             appendCounter = 0
             textLayer =
               beginLayout: ->
+                return if terminate
+
                 #console.log "beginLayout"
 
               endLayout: ->
+                return if terminate
+
                 #console.log "endLayout"
 
                 if DEBUG


    processPDF = (finalCallback) -> (pdf) ->
      counter = pdf.numPages
      for pageNumber in [1..pdf.numPages]
        pdf.getPage(pageNumber).then (page) ->
          # pageNumber is not necessary current page number once promise is resolved, use page.pageNumber instead
          progressCallback (page.pageNumber - 1) / pdf.numPages


                  finalCallback()

              appendText: (geom) ->
                return if terminate

                width = geom.canvasWidth * geom.hScale
                height = geom.fontSize * Math.abs geom.vScale
                x = geom.x
