Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.


  • Please log in to reply
1 reply to this topic

#1 Guest_hollowface_*


  • Guests

Posted 05 June 2016 - 01:43 AM

This post is inspired by this ( http://askubuntu.com/questions/781397/change-filetype-using-zenity ) unanswered question.

The OP has a bash script they've written which launches a graphical file selection, and allows them to convert a PDF file to TXT. The OP wants to be able to have the TXT file saved to the same location as the PDF, with the same name, but have the extension .txt instead of .pdf. I've thrown together a script which does this. I tested the script on Lubuntu 16.04 AMD64. This is just a basic script, with a few bits of precautionary code in it. To anyone thinking of using it on a regular basis I'd suggest expanding it to include more error checking, custom error messages, and popup warnings. Such would make it easier to tell if a conversion fails, or if the script aborts before even attempting the conversion.

Install Script Dependencies:
1. Open your terminal and type:

sudo apt-get install zenity poppler-utils bash

Install Script:
1. Open a text editor and type:
#Browse for PDF
pdf=$(zenity --title "PDF To TXT" --file-selection)
#Determine where to save TXT file
if [[ "$pdf" == "" ]]; then
    exit 1
elif [[ "${pdf: -4}" == ".pdf" ]]; then
    txt="${pdf:0: -3}txt"
elif [[ "${pdf: -4}" == ".PDF" ]]; then
    txt="${pdf:0: -3}txt"
#Convert PDF to TXT if text file does not already exist
if [[ -e "$txt" ]]; then
    exit 1
    pdftotext "$pdf" "$txt"
exit 0
2. Save the script where-ever you want it (eg: ~/script).

Run Script:
1. Open your terminal and type:
bash "/directory/file"
You will need to substitute "/directory/file" for the path to and filename of the script.


BC AdBot (Login to Remove)


#2 NickAu


    Bleepin' Fish Doctor

  • Moderator
  • 13,714 posts
  • Gender:Male
  • Location: Australia

Posted 05 June 2016 - 06:01 AM

Sweet thanks.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users