Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

656
Visualizações
how to digitally sign a PDF document with a certificat using Javascript?

i was looking for a solution to digitally sign a pdf with a self-signed certificat and came across a video in youtube explaining the process using pdf-lib and node-signpdf libraries. However, after following the instructions it didnt work as intended and encountered a problem:

  • i executed the command ( npm i ) and (npm start ) as shown in the github repo of the project.

repo : https://github.com/RichardBray/pdf_sign

Demo ( 8 mins video ) : https://www.youtube.com/watch?v=OFZK5lc70OI&list=PLXUfmx2SIgyICZP-rA84Sle_ghq30W89N&index=4&t=1s

import SignPDF from "./SignPDF";
import fs from "node:fs";
import path from "node:path";

async function main() {
  const pdfBuffer = new SignPDF(
    path.resolve("test_assets/minions.pdf"),
    path.resolve("test_assets/certificate.p12")
  );

  const signedDocs = await pdfBuffer.signPDF();
  const randomNumber = Math.floor(Math.random() * 5000);
  const pdfName = `./exports/exported_file_${randomNumber}.pdf`;

  fs.writeFileSync(pdfName, signedDocs);
  console.log(`New Signed PDF created called: ${pdfName}`);
}

main();
> pdf_sign@1.0.0 start
> npm run build && node dist/index.js

> pdf_sign@1.0.0 build
> ./node_modules/.bin/babel ./src -d ./dist

'.' is not recognized as an internal command
or external, an executable program or a batch file.
  • i tried to run the code using VScode debugger and it displayed the following error :
Uncaught SyntaxError c:\\Users\\ACER\\Documents\\GitHub\\pdf_sign\\src\\index.js:1
import SignPDF from "./SignPDF";
^^^^^^

SyntaxError: Cannot use import statement outside a module
at compileFunction (undefined:352:18)
at wrapSafe (undefined:1031:15)
at Module.\_compile (undefined:1065:27)
at Module.\_extensions..js (undefined:1153:10)
at Module.load (undefined:981:32)
at Module.\_load (undefined:822:12)
at executeUserEntryPoint (undefined:81:12)
at \<anonymous\> (undefined:17:47)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

it appears that the problem is OS related. In fact , the code works fine under linux OS but have some issues with Windows OS related to import command. For windows OS replacing "import" commands with "require" commands solves the problem.

BEFORE:

import SignPDF from "./SignPDF";
import fs from "node:fs";
import path from "node:path";

AFTER :

const SignPDF =  require("./SignPDF");
const fs =  require("node:fs");
const path =  require("node:path");

Edit: Whenever imports are found in the project they should be replaced with require commands . https://jobs.czconsultants.com/utils/convert-imports-to-require-online/0 this website helps converting multiple commands fast

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda