1

I use this script (from here) in order to reduce the size of a pdf file:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \ -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

I have added this within a Dolphin action (service menu) with the line:

Exec=bash -c 'pdf=$(gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook    -sOutputFile=ebook.pdf "%u"); kdialog --title "Shrink" --msgbox "Done! $pdf";';

I would like the output file name to be automatically based on that of the input file, something like: input_xxx.

cipricus
  • 3,444
  • 2
  • 34
  • 85

1 Answers1

1

If you assign the %u value to a shell variable, it should be possible to use standard variable expansion syntax ${var%.ext}_xxx to remove the .pdf extension and add a suffix of your choice:

bash -c 'f="%u"; pdf=$(gs -dQUIET -dBATCH [pdf options] -sOutputFile="${f%.pdf}_xxx" "$f"); ...'
steeldriver
  • 136,215
  • 21
  • 243
  • 336