소스 검색

v2.0.5 - Better GS error handling and debugging messages

master
Gustavo Neves 8 년 전
부모
커밋
96ab46ae72
1개의 변경된 파일16개의 추가작업 그리고 6개의 파일을 삭제
  1. +16
    -6
      pdfScale.sh

+ 16
- 6
pdfScale.sh 파일 보기

@@ -12,7 +12,7 @@
# And: https://gist.github.com/MichaelJCole/86e4968dbfc13256228a # And: https://gist.github.com/MichaelJCole/86e4968dbfc13256228a




VERSION="2.0.4"
VERSION="2.0.5"




###################### EXTERNAL PROGRAMS ####################### ###################### EXTERNAL PROGRAMS #######################
@@ -40,6 +40,7 @@ SCALE="0.95" # scaling factor (0.95 = 95%, e.g.)
VERBOSE=0 # verbosity Level VERBOSE=0 # verbosity Level
PDFSCALE_NAME="$(basename $0)" # simplified name of this script PDFSCALE_NAME="$(basename $0)" # simplified name of this script
OSNAME="$(uname 2>/dev/null)" # Check where we are running OSNAME="$(uname 2>/dev/null)" # Check where we are running
GS_RUN_STATUS="" # Holds GS error messages, signals errors


JUST_IDENTIFY=$FALSE # Flag to just show PDF info JUST_IDENTIFY=$FALSE # Flag to just show PDF info
ADAPTIVEMODE=$TRUE # Automatically try to guess best mode ADAPTIVEMODE=$TRUE # Automatically try to guess best mode
@@ -119,10 +120,11 @@ main() {
finalRet=$? finalRet=$?
fi fi


if [[ $finalRet -eq $EXIT_SUCCESS ]]; then
if [[ $finalRet -eq $EXIT_SUCCESS ]] && isEmpty "$GS_RUN_STATUS"; then
vprint " Final Status: File created successfully" vprint " Final Status: File created successfully"
else else
vprint " Final Status: Errors were detected. Exit status: $finalRet"
vprint " Final Status: Error detected"$'\n'" Exit status: $finalRet"
printError $'\n'"Ghostscript Debug Info:"$'\n'"$GS_RUN_STATUS"
fi fi


return $finalRet return $finalRet
@@ -162,6 +164,12 @@ pageScale() {
local increase=$(echo "scale=0; (($SCALE - 1) * 100)/1" | "$BCBIN") local increase=$(echo "scale=0; (($SCALE - 1) * 100)/1" | "$BCBIN")
vprint " Run Scaling: $increase %" vprint " Run Scaling: $increase %"


GS_RUN_STATUS="$GS_RUN_STATUS$(gsPageScale 2>&1)"
return $? # Last command is always returned I think
}

# Runs GS call for scaling, nothing else should run here
gsPageScale() {
# Scale page # Scale page
"$GSBIN" \ "$GSBIN" \
-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER \ -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER \
@@ -172,7 +180,6 @@ pageScale() {
-sOutputFile="$OUTFILEPDF" \ -sOutputFile="$OUTFILEPDF" \
-c "<</BeginPage{$SCALE $SCALE scale $XTRANS $YTRANS translate}>> setpagedevice" \ -c "<</BeginPage{$SCALE $SCALE scale $XTRANS $YTRANS translate}>> setpagedevice" \
-f "$INFILEPDF" -f "$INFILEPDF"

return $? return $?
} }


@@ -201,7 +208,12 @@ pageResize() {
fi fi


vprint " Run Resizing: $(uppercase "$RESIZE_PAPER_TYPE") ( "$RESIZE_WIDTH" x "$RESIZE_HEIGHT" ) pts" vprint " Run Resizing: $(uppercase "$RESIZE_PAPER_TYPE") ( "$RESIZE_WIDTH" x "$RESIZE_HEIGHT" ) pts"
GS_RUN_STATUS="$GS_RUN_STATUS$(gsPageResize 2>&1)"
return $?
}


# Runs GS call for resizing, nothing else should run here
gsPageResize() {
# Change page size # Change page size
"$GSBIN" \ "$GSBIN" \
-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER \ -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER \
@@ -213,11 +225,9 @@ pageResize() {
-dFIXEDMEDIA -dPDFFitPage \ -dFIXEDMEDIA -dPDFFitPage \
-sOutputFile="$OUTFILEPDF" \ -sOutputFile="$OUTFILEPDF" \
-f "$INFILEPDF" -f "$INFILEPDF"

return $? return $?
} }



########################## INITIALIZERS ######################### ########################## INITIALIZERS #########################


# Loads external dependencies and checks for errors # Loads external dependencies and checks for errors


불러오는 중...
취소
저장