github.com/pdfcpu/pdfcpu@v0.11.1/_scripts/encryptDir.sh (about)

     1  #!/bin/sh
     2  
     3  # Copyright 2018 The pdfcpu Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #	http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  # eg: ./encryptDir.sh ~/pdf/big ~/pdf/out
    18  
    19  if [ $# -ne 2 ]; then
    20      echo "usage: ./encryptDir.sh inDir outDir"
    21      exit 1
    22  fi
    23  
    24  out=$2
    25  
    26  #rm -drf $out/*
    27  
    28  #set -e
    29  
    30  new=_new
    31  
    32  for pdf in $1/*.pdf
    33  do
    34  	#echo $pdf
    35  	
    36  	f=${pdf##*/}
    37  	#echo f = $f
    38  	
    39  	f1=${f%.*}
    40  	#echo f1 = $f1
    41  	
    42  	cp $pdf $out/$f
    43  	
    44  	out1=$out/$f1$new.pdf
    45  	pdfcpu encrypt -verbose -upw=upw -opw=opw $out/$f $out1 &> $out/$f1.log
    46  	if [ $? -eq 1 ]; then
    47          echo "encryption error: $pdf -> $out1"
    48          echo
    49  		continue
    50      else
    51          echo "encryption success: $pdf -> $out1"
    52      fi
    53  	
    54  	pdfcpu validate -verbose -mode=relaxed -upw=upw -opw=opw $out1 &> $out/$f1$new.log
    55  	if [ $? -eq 1 ]; then
    56          echo "validation error: $out1"
    57  		echo
    58  		continue
    59      else
    60          echo "validation success: $out1"
    61      fi
    62  
    63      pdfcpu changeupw -opw opw -verbose $out1 upw upwNew &> $out/$f1$new.log
    64      if [ $? -eq 1 ]; then
    65          echo "changeupw error: $1 -> $out1"
    66          echo
    67  		continue
    68      else
    69          echo "changeupw success: $1 -> $out1"
    70      fi
    71  
    72      pdfcpu validate -verbose -mode=relaxed -upw upwNew -opw opw $out1 &> $out/$f1$new.log
    73      if [ $? -eq 1 ]; then
    74          echo "validation error: $out1"
    75          echo
    76  		continue
    77      else
    78          echo "validation success: $out1"
    79      fi
    80  
    81      pdfcpu changeopw -upw upwNew -verbose $out1 opw opwNew &> $out/$f1$new.log
    82      if [ $? -eq 1 ]; then
    83          echo "changeopw error: $1 -> $out1"
    84          echo
    85  		continue
    86      else
    87          echo "changeopw success: $1 -> $out1"
    88      fi
    89  
    90      pdfcpu validate -verbose -mode=relaxed -upw upwNew -opw opwNew $out1 &> $out/$f1$new.log
    91      if [ $? -eq 1 ]; then
    92          echo "validation error: $out1"
    93          echo
    94  		continue
    95      else
    96          echo "validation success: $out1"
    97      fi
    98  
    99      pdfcpu decrypt -verbose -upw=upwNew -opw=opwNew $out1 $out1 &> $out/$f1.log
   100     	if [ $? -eq 1 ]; then
   101          echo "decryption error: $out1 -> $out1"
   102          echo
   103  		continue
   104      else
   105          echo "decryption success: $out1 -> $out1"
   106      fi
   107  	
   108  	pdfcpu validate -verbose -mode=relaxed $out1 &> $out/$f1$new.log
   109  	if [ $? -eq 1 ]; then
   110          echo "validation error: $out1"
   111      else
   112          echo "validation success: $out1"
   113      fi
   114  	
   115  	echo
   116  	
   117  done