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

            , (err) ->
              error = new Error "PDF page #{ page.pageNumber } rendering error: #{ err.message or err }"
              _.extend error, _.omit err, 'message' if _.isObject err
              throw error

        #pdf.getMetadata(pageNumber).then (metadata) ->

                  finalCallback()

              appendText: (geom) ->
                return if terminate

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