2025-02-02 17:09:39 EST

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_prefix

This 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_prefix

For JPEG output, replace -png with -jpeg.

2025-02-02 17:21:28 EST

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"

Explanation:

If handling multiple extensions (e.g., example.tar.gz where you want example), use:

basename="${file%%.*}"  # Extracts 'example'