Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
sjau committed Aug 26, 2017
1 parent cacc2ca commit 81c7269
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 78 deletions.
4 changes: 4 additions & 0 deletions .directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Dolphin]
Timestamp=2015,10,15,9,55,26
Version=3
ViewMode=1
7 changes: 4 additions & 3 deletions combinePDF/combinePDF.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ levelBookmarks=$(kdialog --radiolist "Shall the pdf names be a superior category

# Prompt file save name
pathName="${filesSorted[1]%/*}"
saveFile=$(kdialog --getsavefilename "${pathName}/Combined.pdf") || exit;
fMessage="Combined"
fExt="pdf"
getSaveFile "PDFs.pdf" "${fMessage}" "${fExt}"


# Loop through the sorted files
h="1"
curPage="0"
for curFile in "${filesSorted[@]}"; do
fileName=${curFile##*/}
fileBase=${fileName%.*}
getFileInfo "${curFile}"
padZero "${h}"
curDocLoc="${tmpStorage}/${paddedCount}${h}"
pdftk "${curFile}" dump_data >> "${curDocLoc}.txt.html"
Expand Down
8 changes: 8 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ getSaveFile () {
}


getFileInfo () {
filePath=${1%/*}"/"
fileName=${1##*/}
fileBase=${fileName%%.*}
fileExt=${name##*.}
}


padZero () {
# Pad the counting to 50 numbers
unset "paddedCount"
Expand Down
16 changes: 7 additions & 9 deletions extractPDF/extractPDF.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

source "/usr/bin/pdfForts/common.sh"

# Ask for range
Range=$(kdialog --title "Define pages" --inputbox "Set the pages you want to extract.
Values are to be seperated by a white space.
Expand All @@ -15,18 +17,14 @@ The order is defines by your range.
if [[ $? != 0 ]]; then
exit;
fi

# Parse the selected file
for arg; do
# Test if it is a file
if [[ -f "${arg}" ]]; then
fName=${arg##*/}
fileNoExt=${arg%.*}
# Prompt for save file
Name=$(kdialog --getsavefilename "${fileNoExt} - extracted.pdf");
if [[ $? != 0 ]]; then
exit;
fi
pdftk "${arg}" cat ${Range} output "${Name}"
fMessage="Extracted"
fExt="pdf"
getSaveFile "${arg}" "${fMessage}" "${fExt}"

pdftk "${arg}" cat ${Range} output "${saveFile}"
fi
done
13 changes: 7 additions & 6 deletions extractTextPDF/extractTextPDF.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

source "/usr/bin/pdfForts/common.sh"

# Prompt to maintain the layout
tplSelect=$(kdialog --title "Maintain Layout" --yesnocancel "Press YES if you want the extracted text to reflect the layout of the PDF")
case "${?}" in
Expand All @@ -20,11 +22,10 @@ for arg; do
# Test if it is a file
if [[ -f "${arg}" ]]; then
# Prompt file save name
fn=${arg%.*}
newFile=$(kdialog --getsavefilename "${fn}.txt");
if [[ $? != 0 ]]; then
exit;
fi
pdftotext ${layout} "${arg}" "${newFile}"
fMessage="Extracted Text"
fExt="txt"
getSaveFile "${arg}" "${fMessage}" "${fExt}"

pdftotext ${layout} "${arg}" "${saveFile}"
fi
done
12 changes: 4 additions & 8 deletions metaPDF/metaPDF.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,10 @@ If no GMT information is specified, the relation between the specified time and
if [[ $? != 0 ]]; then
exit;
fi
fName=${arg##*/}
fileNoExt=${arg%.*}
# Prompt for save file
Name=$(kdialog --getsavefilename "${fileNoExt} - Metainfo.pdf");
if [[ $? != 0 ]]; then
exit;
fi
fMessage="Meta"
fExt="pdf"
getSaveFile "${arg}" "${fMessage}" "${fExt}"
echo "[ /Author (${author})
/CreationDate (${creationdate})
Expand All @@ -155,7 +151,7 @@ If no GMT information is specified, the relation between the specified time and
/DOCINFO pdfmark" > "${pdfMarks}"
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="${Name}" "${arg}" "${pdfMarks}"
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="${saveFile}" "${arg}" "${pdfMarks}"
fi
done
Expand Down
15 changes: 6 additions & 9 deletions ocrPDF/ocrPDF.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source "/usr/bin/pdfForts/common.sh"
# Run some common functions
createTmpDir
deleteTmpDir
checkConfig "ocr§PDF"
checkConfig "ocrPDF"

runOCR () {
i=$1
Expand All @@ -26,7 +26,7 @@ runOCR () {
echo "" >> "${tmpStorage}/output.txt"
((i++))
done
mv "${tmpStorage}/output.txt" "${newFile}"
mv "${tmpStorage}/output.txt" "${saveFile}"
}


Expand All @@ -51,14 +51,11 @@ fi
for arg; do
# Test if it is a file
if [[ -f "${arg}" ]]; then
# Prompt file save name
fn=${arg%.*}
newFile=$(kdialog --getsavefilename "${fn}.txt");
if [[ $? != 0 ]]; then
exit;
fi
# Prompt for save file
fMessage="OCR"
fExt="txt"
getSaveFile "${arg}" "${fMessage}" "${fExt}"
pdftk "${arg}" burst output "${tmpStorage}/pages__%04d.pdf"
runOCR
cleanUp
fi
done
13 changes: 6 additions & 7 deletions pdfaPDF/pdfaPDF.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/usr/bin/env bash

source "/usr/bin/pdfForts/common.sh"

# Loop through the selected files
for arg; do
# Test if it is a file
if [[ -f "${arg}" ]]; then
fName=$(arg##*/)
fileNoExt=${arg%.*}
# Prompt for save file
Name=$(kdialog --getsavefilename "${fileNoExt} - PDFA.pdf");
if [[ $? != 0 ]]; then
exit;
fi
gs -dPDFA -dBATCH -dNOPAUSE -dNOOUTERSAVE -dUseCIEColor -sProcessColorModel=DeviceCMYK -sDEVICE=pdfwrite -sOutputFile="${Name}" "${arg}"
fMessage="PDFA"
fExt="pdf"
getSaveFile "${arg}" "${fMessage}" "${fExt}";
gs -dPDFA -dBATCH -dNOPAUSE -dNOOUTERSAVE -dUseCIEColor -sProcessColorModel=DeviceCMYK -sDEVICE=pdfwrite -sOutputFile="${saveFile}" "${arg}"
fi
done
12 changes: 5 additions & 7 deletions qualityPDF/qualityPDF.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ deleteTmpDir
for arg; do
# Test if it is a file
if [[ -f "${arg}" ]]; then
fName=${arg##*/}
fileNoExt=${arg%.*}
# Prompt for save file
Name=$(kdialog --getsavefilename "${fileNoExt} - quality.pdf");
if [[ $? != 0 ]]; then
exit;
fi
fMessage="Quality"
fExt="pdf"
getSaveFile "${arg}" "${fMessage}" "${fExt}";

curFile="${arg}"
# Check if color change is required
if [[ "${Color}" = "Gray" ]]; then
Expand All @@ -51,7 +49,7 @@ for arg; do
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dDownsampleColorImages=true -dColorImageResolution=${Resolution} -dNOPAUSE -dBATCH -sOutputFile="${tmpStorage}/resize.pdf" "${curFile}"
curFile="${tmpStorage}/resize.pdf"
fi
mv "$curFile" "${Name}"
mv "$curFile" "${saveFile}"
fi
done

Expand Down
9 changes: 7 additions & 2 deletions rmPasswdPDF/rmPasswdPDF.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

source "/usr/bin/pdfForts/common.sh"

# Loop through the selected files
for arg; do
# Test if it is a file
Expand All @@ -10,8 +12,11 @@ for arg; do
if [[ $? != 0 ]]; then
exit;
fi
fileNoExt=${arg%.*}
pdftk "${arg}" input_pw ${Passwd} output "${fileNoExt} - no Pwd.pdf"
# Prompt for save file
fMessage="no Pwd"
fExt="pdf"
getSaveFile "${arg}" "${fMessage}" "${fExt}";
pdftk "${arg}" input_pw ${Passwd} output "${saveFile}"
fi
done

Expand Down
13 changes: 6 additions & 7 deletions rotatePDF/rotatePDF.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

source "/usr/bin/pdfForts/common.sh"

# Ask for range
Rotate=$(kdialog --menu "Chose rotation (clockwise):" East "90°" South "180°" West "270°");
if [[ $? != 0 ]]; then
Expand All @@ -10,13 +12,10 @@ fi
for arg; do
# Test if it is a file
if [[ -f "${arg}" ]]; then
fName=${arg##*/}
fileNoExt=${arg%.*}
# Prompt for save file
Name=$(kdialog --getsavefilename "${fileNoExt} - rotated.pdf")
if [[ $? != 0 ]]; then
exit;
fi
pdftk "${arg}" cat 1-end${Rotate} output "${Name}"
fMessage="Rotated"
fExt="pdf"
getSaveFile "${arg}" "${fMessage}" "${fExt}";
pdftk "${arg}" cat 1-end${Rotate} output "${saveFile}"
fi
done
15 changes: 5 additions & 10 deletions searchablePDF/searchablePDF.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ deleteTmpDir
for arg; do
# Test if it is a file
if [[ -f "${arg}" ]]; then
fName=${arg##*/}
fileNoExt=${fName%.*}
# Prompt for save file
Name=$(kdialog --getsavefilename "${fileNoExt} - searchable.pdf");
if [[ "${?}" != 0 ]]; then
exit;
fi
fMessage="Searchable"
fExt="pdf"
getSaveFile "${arg}" "${fMessage}" "${fExt}";

cd "${tmpStorage}" || exit;

Expand All @@ -47,12 +44,10 @@ for arg; do
if [[ "${?}" != 0 ]]; then
touch "${curFile}.html"
fi
hocr2pdf -i "${curFile}" -r 300 -o "${curFile}.new.pdf" < "${curFile}.html"
hocr2pdf -i "${curFile}" -o "${curFile}.new.pdf" < "${curFile}.html"

done
xxxName=$(kdialog --getsavefilename "${fileNoExt} - searchable.pdf");

pdftk "pages__"*.new.pdf cat output "${Name}"
pdftk "pages__"*.new.pdf cat output "${saveFile}"

fi
done
Expand Down
4 changes: 1 addition & 3 deletions stampPDF/stampPDF.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ for curFile in "${filesSorted[@]}"; do
docNr="${paddedCount}${doc}"

# Get file info and dir name
fileName=${curFile##*/}
fileBase=${fileName%%.*}
fileExt=${curFile##*.}
getFileInfo "${curFile}"
fPath=$(readlink -f "${curFile}")
destDir=$(dirname "${fPath}")
# Start the file manipulation
Expand Down
12 changes: 5 additions & 7 deletions watermarkPDF/watermarkPDF.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ createOdt;
for arg; do
# Test if it is a file
if [[ -f "${arg}" ]]; then
# Prompt file save name
fn=${arg%.*}
newFile=$(kdialog --getsavefilename "${fn} - ${tplMessage}.pdf")
if [[ $? != 0 ]]; then
exit;
fi
# Prompt for save file
fMessage="Watermark"
fExt="pdf"
getSaveFile "${arg}" "${fMessage}" "${fExt}";
libreoffice --headless --invisible --convert-to pdf "${tmpStorage}/draft.odt"
convert -density 300 "${tmpStorage}/draft.pdf" -quality 90 "${tmpStorage}/draft.png"
convert "${tmpStorage}/draft.png" -transparent white -background none "${tmpStorage}/draft2.pdf"
pdftk "${arg}" multistamp "${tmpStorage}/draft2.pdf" output "${newFile}"
pdftk "${arg}" multistamp "${tmpStorage}/draft2.pdf" output "${saveFile}"
fi
done

0 comments on commit 81c7269

Please sign in to comment.