github.com/pdfcpu/pdfcpu@v0.11.1/_scripts/encryptFile.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: ./encryptFile.sh ~/pdf/1mb/a.pdf ~/pdf/out 18 19 if [ $# -ne 2 ]; then 20 echo "usage: ./encryptFile.sh inFile outDir" 21 exit 1 22 fi 23 24 new=_new 25 26 f=${1##*/} 27 f1=${f%.*} 28 out=$2 29 30 #rm -drf $out/* 31 32 #set -e 33 34 cp $1 $out/$f 35 36 out1=$out/$f1$new.pdf 37 pdfcpu encrypt -verbose -upw upw -opw opw $out/$f $out1 &> $out/$f1.log 38 if [ $? -eq 1 ]; then 39 echo "encryption error: $1 -> $out1" 40 exit $? 41 else 42 echo "encryption success: $1 -> $out1" 43 fi 44 45 pdfcpu validate -verbose -mode=relaxed -upw upw -opw opw $out1 &> $out/$f1$new.log 46 if [ $? -eq 1 ]; then 47 echo "validation error: $out1" 48 exit $? 49 else 50 echo "validation success: $out1" 51 fi 52 53 pdfcpu changeupw -opw opw -verbose $out1 upw upwNew &> $out/$f1$new.log 54 if [ $? -eq 1 ]; then 55 echo "changeupw error: $1 -> $out1" 56 exit $? 57 else 58 echo "changeupw success: $1 -> $out1" 59 fi 60 61 pdfcpu validate -verbose -mode=relaxed -upw upwNew -opw opw $out1 &> $out/$f1$new.log 62 if [ $? -eq 1 ]; then 63 echo "validation error: $out1" 64 exit $? 65 else 66 echo "validation success: $out1" 67 fi 68 69 pdfcpu changeopw -upw upwNew -verbose $out1 opw opwNew &> $out/$f1$new.log 70 if [ $? -eq 1 ]; then 71 echo "changeopw error: $1 -> $out1" 72 exit $? 73 else 74 echo "changeopw success: $1 -> $out1" 75 fi 76 77 pdfcpu validate -verbose -mode=relaxed -upw upwNew -opw opwNew $out1 &> $out/$f1$new.log 78 if [ $? -eq 1 ]; then 79 echo "validation error: $out1" 80 exit $? 81 else 82 echo "validation success: $out1" 83 fi 84 85 pdfcpu decrypt -verbose -upw upwNew -opw opwNew $out1 $out1 &> $out/$f1.log 86 if [ $? -eq 1 ]; then 87 echo "decryption error: $out1 -> $out1" 88 exit $? 89 else 90 echo "decryption success: $out1 -> $out1" 91 fi 92 93 pdfcpu validate -verbose -mode=relaxed $out1 &> $out/$f1$new.log 94 if [ $? -eq 1 ]; then 95 echo "validation error: $out1" 96 exit $? 97 else 98 echo "validation success: $out1" 99 fi 100 101