Sparticuz / node-qpdf2

A Content Preserving transformations on PDFs wrapped around QPDF
MIT License
20 stars 16 forks source link

Add --replace-input flag for saving as a same name. #26

Closed HarshilSySCreations closed 1 year ago

HarshilSySCreations commented 1 year ago

Hi @Sparticuz ,

Many thanks for maintaining this repo. It's been a great help. Here I would like to request a feature to add --replace-input flag to allow users to save password-protected files with the same name so that we don't have to delete old password-less files.

here is the error that I've got,

UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "
qpdf: input file and output file are the same; use --replace-input to intentionally overwrite the input file

code snippet:

      setTimeout(() => {
        try {
          const passProtectedPDF = async (): Promise<any> => {
            console.log('[*] into passProtectedPDF!');
            const pdf = {
              input: pdfFile,
              output: pdfFile,
              password: getHCNo,
            };
            await qpdf2.encrypt(pdf);
            console.log('[*] end of passProtectedPDF!');
          };
          console.log('[*] passProtectedPDF called!');
          resolve(passProtectedPDF());
        } catch (err) {
          console.log(err);
        }
      }, 1000);
Sparticuz commented 1 year ago

Thanks for the issue! I've released this in v4.1.0.

HarshilSySCreations commented 1 year ago

Thanks for the issue! I've released this in v4.1.0.

Wow, what a speed. Respect.