jjwilly16 / node-pdftk

A wrapper for PDF Toolkit with streams and promises.
MIT License
141 stars 34 forks source link

Stamp Method does not call Then or Catch #15

Closed cfernandomaciel closed 6 years ago

cfernandomaciel commented 6 years ago

I have the following piece of code:


addWatermark: (input, output, cb) => {
        pdftk
            .input(input)
            .stamp('./pdftools/logo.pdf')
            .output(output)
            .then((buffer) => {
                logger.info('WATTERMARK-APPLYING-LOG: going to call watermarkCallback');
                cb("", "pdf has been branded", "");
            })
            .catch((err) => {
                logger.info("PDF-BRANDING - WATTERMARK-APPLYING-ERROR: " + err);
                cb(err, null, err);
            });

    }

It's a pretty straight forward piece of code, no magic, nothing really to it, just vanilla node-pdftk. It executes the input method, then the stamp one, and the output. The problem is that it never reaches the Then, and Catch methods. It just falls outside the method.

I tried many different approaches, but I cannot seem to find the reason.

Input, output, and cb params are loaded correctly, but yet, Then and Catch do not work.

I'm using node-pdfk v 1.3.0

edit: I've updated to node-pdftk v 1.3.1 (latest) and the bug continues.

jjwilly16 commented 6 years ago

The only promise-returning method is output, so unfortunately any errors that happen before that are likely to be swallowed. If I had to guess, I would say maybe your stamp file path is bad.

2.0 will fix any of these issues caused by my oversights in the current release. I have to write a lot more tests before I release it but you can check out the 2.0 branch and see if that fixes the problem. It should be fairly stable.

jjwilly16 commented 6 years ago

18 should fix this. Closing the issue