M: Linux command to export PDF pages as sequential images
G: You can use
pdftoppm to export PDF pages as sequential images:
pdftoppm -png input.pdf output_prefixThis will generate images like output_prefix-1.png,
output_prefix-2.png, etc.
For a specific page range, use -f (first page) and
-l (last page):
pdftoppm -png -f 2 -l 5 input.pdf output_prefixFor JPEG output, replace -png with
-jpeg.
M: In bash, how do you extract the file name and extension from a variable?
G: You can extract the filename and extension from a variable in Bash using parameter expansion:
file="example.tar.gz"
# Extract the filename without extension
filename="${file%.*}"
# Extract the extension
extension="${file##*.}"
echo "Filename: $filename"
echo "Extension: $extension"${file%.*} removes the last .* and gives
example.tar (useful for single extensions but not for
multi-part ones like .tar.gz).${file##*.} extracts everything after the last dot,
giving gz.If handling multiple extensions (e.g., example.tar.gz
where you want example), use:
basename="${file%%.*}" # Extracts 'example'