-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconvertTodocx.sh
More file actions
31 lines (24 loc) · 772 Bytes
/
convertTodocx.sh
File metadata and controls
31 lines (24 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
inputFilePath=$1
outputFilePath=$2
keepActive=$3
# Check if input file exists
if [ ! -f "$inputFilePath" ]; then
echo "Input file does not exist: $inputFilePath"
exit 1
fi
# Extract text from PDF using pdftotext (requires Poppler installed)
tempTextFilePath="$(mktemp).txt"
pdftotext -layout "$inputFilePath" "$tempTextFilePath"
if [ ! -f "$tempTextFilePath" ]; then
echo "Failed to extract text from PDF: $inputFilePath"
exit 1
fi
# Convert extracted text to DOCX using pandoc (requires pandoc installed)
if [ -z "$outputFilePath" ]; then
outputFilePath="${inputFilePath%.pdf}.docx"
fi
pandoc "$tempTextFilePath" -o "$outputFilePath"
# Clean up temporary text file
rm "$tempTextFilePath"
echo "Conversion complete: $outputFilePath"