# 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.

Example:

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.

Example:

\documentclass[headheight=1.2cm,headsepline,twoside]{scrartcl}
\usepackage[left=0.5in, right=0.5in,top=1in, bottom=2.8cm,footskip=18mm]{geometry}

\usepackage{hyperref}
\hypersetup{
linktoc=all,     %set to all if you want both sections and subsections linked
}

\usepackage{tabularx}
\usepackage{lipsum}
\usepackage{pdfpages}
\usepackage[english]{babel}

\cfoot[]{Center footer -- \thepage{} --}
\ifoot[]{Inside footer}
\ofoot[]{Outside footer}

% Easy interface
%\deftripstyle{pdfincl}
%  {}
%  {}
%  {Another inside footer}
%  {}
%  {Another outside footer}

% Expert interface
\newpagestyle{pdfincl}
(0pt,0pt)% no above rule
}
}
}
(0pt,0pt)% no above rule
}
{% FOOTER
(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
\end{tabularx}%
}
{% footer, single side
Another inside footer\hfil Another outside footer
}
(0pt,0pt)% no rule below footer
}

\begin{document}

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

\maketitle
\tableofcontents
%\section{Section Name}
%\section{Blah}
%\lipsum[3-5]

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

# 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)


# How to Extract filename and extension in Bash?

If you want to get the filename (without extension) and the extension separately, see the code below.

First, get file name without the path:

#!/bin/bash

#get the  file in a directory

filename=ls *.pdf
#print file name
echo $filename extension="${filename##*.}"
echo $extension filename="${filename%.*}"
echo $filename # Website to Install MACOS app with the terminal command Search and Install any app on MacOS from the website, https://macappstore.org through terminal command. # How to keep the converted file name same as the source file name with ImageMagic? With ImageMagic you can easily call a file with its extension from a directory and save the converted file to source file name. Here is an example converting from pdf into jpg: convert *.pdf -set filename:base "%[basename]" "%[filename:base].jpg" # 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) print(kn)  # 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 #!/bin/bash # 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 y=25 # addition : this is another single line comment z=$(($x +$y))

# echo result to console
echo $x +$y = \$z

Output:

## 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 <<.

Bash Script File

#!/bin/bash

# this is a single line comment in bash
echo Learn Bash Scripting

<<COMMENT
This is a multiple line comment
In Bash Scripting
COMMENT
echo Good Day!

<<COMMENT
This is a multiple line comment
End of the example
COMMENT

Output:

### Conclusion

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.

#!/bin/bash
convert -density 300 -quality 90 input.pdf output.png

4) At the command line, run mybashfile.sh

## Syntax

The syntax is:
sh mybashfile.sh

OR

bash  mybashfile.sh