Skip to content

Commit

Permalink
Convert pdfs to pngs
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Marston <[email protected]>
  • Loading branch information
richardmarston committed Dec 14, 2021
1 parent 77fe6af commit 713814b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from alpine:latest

run apk update
run apk add python3 py3-pip
run apk add python3 py3-pip poppler-utils
run /usr/bin/pip3 install pyxb openpyxl
copy . /excel2xml
cmd sh /excel2xml/process_all_xlsx.sh
10 changes: 9 additions & 1 deletion process_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
INPUT_DIR=$1
OUTPUT_DIR=$2

find $INPUT_DIR -type f -not -name '*.xlsx' -exec sh -c '
find $INPUT_DIR -type f -not \( -name '*.xlsx' -o -name '*.pdf' \) -exec sh -c '
FILE="$0"
OUTPUT_DIR="$1"
FILE_NO_SPACES=$(basename "${FILE}" | tr '[:blank:]' '_')
cp "$FILE" "$OUTPUT_DIR/$FILE_NO_SPACES"
' {} ${OUTPUT_DIR} ';'

find $INPUT_DIR -type f -name '*.pdf' -exec sh -c '
FILE="$0"
OUTPUT_DIR="$1"
FILE_NO_SPACES=$(basename "${FILE}" | tr '[:blank:]' '_')
pdftoppm -png -singlefile "$FILE" "$OUTPUT_DIR/$FILE_NO_SPACES"
echo "Converting $FILE to $OUTPUT_DIR/${FILE_NO_SPACES}.png"
' {} ${OUTPUT_DIR} ';'
6 changes: 5 additions & 1 deletion xlsx2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ def switch_uriType(argument):
name = cell_str(sheet_ranges, 38, 3+index)
drawingType = cell_str(sheet_ranges, 39, 3+index)
uriType = cell_str(sheet_ranges, 40, 3+index)
uri = cell_str(sheet_ranges, 41, 3+index).strip().replace(' ', '_')
uri = cell_str(sheet_ranges, 41, 3+index).strip().replace(' ', '_')

if uri.endswith('.pdf'):
uri = uri + '.png'

if name != 'None' and uri!='None' :
drawing = IEC62559.Drawing()
resourcestr = IEC62559.Resource_String(uri)
Expand Down

0 comments on commit 713814b

Please sign in to comment.