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 PDFKit Library Example to Encrypt PDF Documents With Password in Javascript on Command Line

Posted on January 17, 2023

 

 

Welcome folks today in this blog post we will be using the pdfkit library to encrypt pdf documents with password in javascript. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to install the below libraries using the below command as shown below

 

 

npm init -y

 

 

npm i pdfkit

 

 

After that you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const PDFDocument = require("pdfkit");
const fs = require("fs");
var options = {
    userPassword: "123456",
}
// Create a document
const doc = new PDFDocument(options);
// Pipe its output somewhere, like to a file or HTTP response
// See below for browser usage
doc.pipe(fs.createWriteStream("output.pdf"));
doc.addPage()
// Finalize PDF file
doc.end();

 

 

Ass you can see we are importing the pdfkit library at the top and then we are making the pdf document and adding two empty pages and after that we are declaring the password and then encrypting the pdf document with that password using the  PDFDocument() constructor. And then we are saving the pdf document using the fs module.

 

 

node index.js

 

 

 

 

 

 

Recent Posts

  • Android Java Tutorial to Change Styles & Visibility of System Bars (Top, Action & Status) Full Example
  • Android Java Project to Display & Play Audio Files From Storage inside ListView Using MediaPlayer Class
  • Android Java Project to Build MP4 Video to MP3 Audio Converter Using MediaMuxer Class
  • Android Java Project to Merge Multiple PDF Documents From Gallery Using iTextPDF Library
  • Android Java Project to Detect System Hardware & System CPU Info & Display inside TextView Widget
  • 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