chunyenHuang / hummusRecipe

A powerful PDF tool for NodeJS based on HummusJS.
https://hummus-recipe.s3.amazonaws.com/docs/Recipe.html
MIT License
341 stars 91 forks source link

PDF encryption take too long? #197

Closed SolidTears closed 4 years ago

SolidTears commented 4 years ago

just use this, and notice that when i encrypt my pdf, it take too long and cause server socket timeout, is there any reason for this? and how to fix it ?

the pdf fairly simple report pdf, with 500kb size

heres the snippet :

await fsPromises.writeFile(`./stash/input.pdf`, result, { encoding: 'base64' })
          .then(() => {
            logger.debug('pdf saved');

            const pdfDoc = new HummusRecipe(`./stash/input.pdf`, `./stash/output.pdf`);
            logger.debug("start encrypt");
            pdfDoc
              .encrypt({
                userPassword: body.password,
                userProtectionFlag: 3
              })
              .endPDF();
            logger.debug("encrypt done");
          })
          .catch(er => {
            logger.error(er);;
          });
chunyenHuang commented 4 years ago

Unfortunately encryption has to write to a new file instead of caching in memory, can you check if it's permission issue?

SolidTears commented 4 years ago

sorry i might be not put enough detail, while its indeed socket time out, but the encryption still work , it just took a long time , i test for 3kb pdf work just fine, 500kb on the other hand need about 2 minutes, is there any workaround for this ?

SolidTears commented 4 years ago

might need to add new comment for anyone find same problem

while this library is great, it work just fine on local side, but on server it too source consuming, i change to use qpdf with exec for my encryption and merging need, still an awesome library nontheless, thanks !