                 counter--
                 if counter == 0
                   progressCallback 1.0
-                  finalCallback finalError
+                  finalCallback()
 
               appendText: (geom) ->
                 width = geom.canvasWidth * geom.hScale


    processPDF = (finalCallback) -> (pdf) ->
      counter = pdf.numPages
      finalError = null

      for pageNumber in [1..pdf.numPages]
        if finalError
          # We call finalCallback only after all pages have been processed and thus callbacks called
          counter--
          finalCallback finalError if counter == 0
          return

        pdf.getPage(pageNumber).then (page) ->
          if finalError
            # We call finalCallback only after all pages have been processed and thus callbacks called
            counter--
            finalCallback finalError if counter == 0
            return

          # pageNumber is not necessary current page number once promise is resolved, use page.pageNumber instead
          progressCallback (page.pageNumber - 1) / pdf.numPages


            page.render(renderContext).then ->
              return # Do nothing
            , (error) ->
              # TODO: This exception is not nicely displayed in the console, future.wrap seems to remove payload
              throw new Error error

        pdf.getMetadata(pageNumber).then (metadata) ->
          # TODO: If we will process metadata, too, we have to make sure finalCallback is called after only once after everything is finished
