Encrypt PDF with pdf in Linux or MacOS

QPDF is SUPER excellent PDF command line utality for Linux !!! It is SUPER excellent tool, being very powerful, able to perform highly difficult & specific operations on PDF files ……. .QPDF is a program that can be used to linearize (web-optimize), encrypt (password-protect), decrypt, and inspect PDF files from the command-line. 

Install qpdf by entering the following commands in the terminal:

sudo apt update
sudo apt install qpdf

General syntax to encrypt pdf

To encrypt PDF file:
qpdf --encrypt user-password owner-password key-length [restrictions] -- inputfile.pdf outputfile.pdf

The User password, or sometimes called the “open” password is used to open a PDF file if a password is set. The other password, the Owner passwordis used to set what users can do with the PDF. It controls things like if a user is allowed to print, copy or modify a PDF. Either or both of the user password and the owner password may be empty strings. The value for key-length may be 40, 128, or 256. When no additional restrictions are given, the default is to be fully permissive.


qpdf --linearize --encrypt "bettersolution4u" "MKS" 128 --print=full --modify=none --extract=n --use-aes=y -- inputfile.pdf outputfile.pdf

How to Add Header and Footer on Included PDF in LaTeX?

Using your current settings, the pdfpages inserts the pages of an external PDF file as full page additions to your existing document. That is, the external file page setup is copied to the “main” output PDF on a page-by-page basis. The “main” file’s page setup (including header/footer) is ignored.

If you wish to include the same header/footer style of your main document for each of the \includepdf pages, then you need to specify this using the pagecommand key-value.


\usepackage[left=0.5in, right=0.5in,top=1in, bottom=2.8cm,footskip=18mm]{geometry}

    colorlinks=true, %set true if you want colored links
    linktoc=all,     %set to all if you want both sections and subsections linked
    linkcolor=blue,  %choose some color if you want links to stand out


\chead[]{Center header}
\ihead[]{Inside header}
\ohead[]{Outside header}
\cfoot[]{Center footer -- \thepage{} --}
\ifoot[]{Inside footer}
\ofoot[]{Outside footer}

% Easy interface
%  {}
%  {And a center header}
%  {}
%  {Another inside footer}
%  {}
%  {Another outside footer}

% Expert interface
  (0pt,0pt)% no above rule
  {% header, even pages
   \hfil And a center header\hfil
  {% header, odd pages
   \hfil And a center header\hfil
  {% header, single side
   \hfil And a center header\hfil
  %(\textwidth,0.4pt)% rule below header
  (0pt,0pt)% no above rule
  (0pt,0pt)% no separation rule
  {% footer, even pages
   Another outside footer\hfil Another inside footer
  {% footer, odd pages
  \begin{tabularx}{\textwidth}{|l|>{\centering\arraybackslash} X|r|}\hline 
     Another inside footer &  Another outside footer & \hfill Page no.\thepage \\ \hline 
  {% footer, single side
   Another inside footer\hfil Another outside footer
  (0pt,0pt)% no rule below footer

\AtBeginDocument{\renewcommand\contentsname{Table of Contents}}% Custom name of TOC

\title{Title of the Your Contents Here}
\author{Md Kutubuddin Sardar}

%\section{Section Name}

\includepdf[addtotoc={1, section, 1, Included PDF,tag},
%\includepdf[addtotoc={1, subsection, 1, Included PDF,tag}, turn=false,frame,scale=0.9,pages=-,pagecommand={\thispagestyle{pdfincl}}]{preposition}
%\section{Section Name}

How to Remove Files with Different Specific Extensions in Linux?

We use the ‘rm‘ (Remove) command to remove files with a specified extensions in Linux. It is a fundamental command-line utility for removing system files, directories, symbolic links, device nodes, pipes, and sockets in Linux. The command is straightforward to use and has the following syntax:

rm <filename1> <filename2> ... <filenameN>

Here, ‘filename1‘, ‘filename2‘, etc. are the names of the files including full path. If the files are in the same directory then, as you might already know, there is no need to write down full paths.

Suppose the temporary file such as file.aux, file.log, file.out are generated for compiling latex file. We can delete these easily as below:

rm -r *.out *.log *.aux

Replace whitespace of a file name with underscore using Python

If you need to replace all the whitespace of all filenames in a directory with underscore ( _ ), then the following codes are the solution for you.

import re
import os
import glob

for filename in glob.glob('*.pdf'): #calling filename from directory by its extension
    name, ext = os.path.splitext(filename) # separate file name and its extension
    name = name.replace(" ", "_") # replace any whitespace by underscore
    os.rename(filename,str(name)+'.pdf') # os.rename(OldName,NewName) 

Call image from a directory by extension and return the same file name with Python

Sometimes we have to open a random image with specific image extension from a directory and return it with the same file name. In that case this code is very effective.

from PIL import Image

#======Call image by extension and return same name=======
import os
import glob
for k in glob.glob('*.jpg'):
    print k
    i = Image.open(k)
    kn, kext = os.path.splitext(k)

How to Comment Out a Block of Codes with Bash Script?

Comments can be used to explain a programming code. It is also used to make the codes are readable as well as to prevent execution when checking code.

There can be two types of comments, a single line comment, and another multiline comment. In this tutorial, we shall learn how to provide single line and multiple line comments in a Bash Script file. A basic discussion of bash script has been done here.

Bash Single Line Comment

To make a single line comment, it is enough to put a # (hash symbol) at the beginning of that line.

Example for Bash Single Line Comments

Bash Script File

# this is a single line comment in bash
echo Learn Bash Scripting
x=12 # this is also a comment, but after the command in same line
# addition : this is another single line comment
z=$(($x + $y))
# echo result to console
echo $x + $y = $z


Bash Multiline Comment

To write multiline comments in bash scripting, enclosing the comments between <<COMMENT and COMMENT. Following is an example of demonstrating multiple line comments or block comments in Bash Scripting.

In this example, we write multiline comments using <<.

Example for Bash multiline comments

Bash Script File

# this is a single line comment in bash
echo Learn Bash Scripting
    This is a multiple line comment
    In Bash Scripting
echo Good Day!
    This is a multiple line comment
    End of the example



In this Bash Tutorial, we have learned how to write a single line comment and multiline comments in Bash script file.

How to Make a Bash Script Executable?

Why not automatically do that if you constantly use the same set of commands on the command line?

It is used in Linux filesystems to automate repetitive activities. It could have a group of commands or a single command or it could include features such as loops, functions, conditional constructs etc. A Bash script is effectively a computer programme written in the language of Bash programming.

To create a bash file follow the steps bellows:

1) Create a new text file with a .sh extension.

I created a new file called mybashfile.sh for my code.

2) Add #!/bin/bash to the top of it.

This is necessary for the “make it executable” part.

3) Add lines that you’d normally type at the command line.

For example, here are the full contents of the file I use to convert a pdf file to an image with ImageMagic.

convert -density 300 -quality 90 input.pdf output.png

4) At the command line, run mybashfile.sh 


The syntax is:
sh mybashfile.sh 


bash  mybashfile.sh 

5) Run it whenever you need!