Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Node.js qpdf Library Example to Encrypt PDF Documents With Password Using Child Process Module

Posted on January 17, 2023

Welcome folks today in this blog post we will be encrypting pdf documents with password using the qpdf library in command line using child process. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to install the qpdf library globally inside your system on the command line

 

 

npm i -g qpdf

 

 

After that you need to use this library using the below command as shown below

 

 

1
qpdf --encrypt user-password key-length flags -- source-file-path destination-file-path

 

 

As you can see we are using the above command here you need to replace the path of the input pdf file and output pdf file. And here you need to replace the password you need to encrypt. This command will translate into as shown below

 

 

qpdf --encrypt test 40 sample.pdf encrypted.pdf

 

 

And now you can make the index.js file inside the node.js project using the child_process() module as shown below

 

 

index.js

 

 

Python
1
2
3
4
5
6
7
8
9
10
11
12
let exec = require('child_process').exec
 
let cmd = "qpdf --encrypt test 40 sample.pdf encrypted.pdf"
 
exec(cmd,(err) => {
    if(err){
        console.log(err)
    }
    else{
        console.log("PDF encrypted")
    }
})

 

Recent Posts

  • Android Java Project to Download Multiple Images From URL With Progressbar & Save it inside Gallery
  • Android Java Project to Capture Image From Camera & Save it inside Gallery
  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme