Problem in refreshing a text editor (gedit) for scanned pdf


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in refreshing a text editor (gedit) for scanned pdf
# 1  
Old 05-27-2016
Tools Problem in refreshing a text editor (gedit) for scanned pdf

Dear Friends,
I am using Ubuntu 15.10, 34 bit system. I added a Nautilus-Actions script in shell script to convert PDF files to text. There are 2 types of PDF

1. Scanned PDF -- Not OCR type -- When I convert it to text it work , but as the part it must (text file) open in gedit . But I can see a blank file
eventhough it came in real file...

2. For Normal PDF (searcable one) -- it works fine

I add my code for your reference ... please advise what I do to avoid this issue..

Code:
#!/bin/bash
cd $1
if [[ $2 = *.pdf ]]; then
  #echo pdf > "anes.txt"
  MYFONTS=$(pdffonts -l 5 "$3" | tail -n +3 | cut -d' ' -f1 | sort | uniq)
  if [ "$MYFONTS" = '' ] || [ "$MYFONTS" = '[none]' ]; then
    #Scanned PDF
    convert -density 300 "$3" "${3%.*}.tiff"
    tesseract "${3%.*}.tiff" "$3"
    sleep 2
    rm -f "${3%.*}.tiff"
    gedit "${3/%.*}.txt"
  else
    pdftotext "$3"
    gedit "${3/%.pdf/.txt}"
  fi
elif [[ $2 = *.tif ]] ||  [[ $2 = *.tiff ]] || [[ $2 = *.jpg ]] || [[ $2 = *.jpeg ]] || [[ $2 = *.png ]] || [[ $2 = *.gif ]]; then
   tesseract "$3" "${3%.*}"
   gedit "${3/%.*}.txt"
else
  # Not implemented case...
  #echo Nothing to do > "anes.txt"
fi

Waiting for your fast response

Thanks

Anes
# 2  
Old 05-27-2016
Just because you had a real file doesn't mean it had real contents. If it's a scanned PDF, something has to do optical character recogntion, and pdf2text does not. Hence the PDF's you get are empty.
# 3  
Old 05-27-2016
It's not clear what $2 and $3 are ..

It looks like you convert $3, so I assume that's file.pdf

tesseract's output would be in file.pdf.txt since you didn't use ${3%.*} as you did elsewhere. But then you try to open ${3/%.*}.txt instead...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. HP-UX

Best text to pdf converter for Hp/UX 11.31

Hi, Can anyone tell me the best converter I can use to convert text to pdf for HP/UX 11.31? Thanks, Linda (0 Replies)
Discussion started by: lnemitz
0 Replies

2. Shell Programming and Scripting

Text to pdf

Is there a way to covert te attached text file to a pdf? I have tried: enscript-p output.ps article.txt PRE.cjk { font-family: "WenQuanYi Micro Hei",monospace; }PRE.ctl { font-family: "Lohit Hindi",monospace; }P { margin-bottom: 0.08in; } awk '{ A=$2; next} END { for (i in A) print... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. Shell Programming and Scripting

Pdf to text

Is there a way using the pdf to text utility to convert all the pdf in a given directory? So instead of one at a time: pdftotext pdftotext hp-manual.pdf hp-manual.txt a directory of 50 pdf files would be converted: pdftotext /home/dnascopev/Desktop/PDF.pdf /home/dnascopev/Desktop/PDF.txt ... (6 Replies)
Discussion started by: cmccabe
6 Replies

4. UNIX for Advanced & Expert Users

PDF to Text Conversion

Hi Guys, My OS is Suse Linux.. Is there a Command to convert PDF file to Text?? Cheers!!!!! (2 Replies)
Discussion started by: mac4rfree
2 Replies

5. Red Hat

create pdf of text file help

Can someone please tell me why this is not working? I have created numerous pdf's from text files by following these instructions and this time it is not working. Convert jpeg files to PDF under Linux | bitPrison.net convert /home/liveuser/Documents/hw7 /home/liveuser/Documents/hw7.pdf... (5 Replies)
Discussion started by: cokedude
5 Replies

6. Solaris

weird problem - terminal not refreshing; sleep not terminating

Hi, I am having a wierd problem in one of the Solaris server. root@ussd # uname -a SunOS ussd 5.8 Generic_108528-24 sun4u sparc SUNW,Sun-Fire-280R The problem is that terminal is not refreshing when we run commands like prstat, tail -f "some log file", sar -u 1 10 Also, sleep... (3 Replies)
Discussion started by: vikas027
3 Replies

7. UNIX for Dummies Questions & Answers

Pasting text in VI editor from a different editor

Hi, I knw its a silly question, but am a newbie to 'vi' editor. I'm forced to use this, hence kindly help me with this question. How can i paste a chunk 'copied from' a different editor(gedit) in 'vi editor'? As i see, p & P options does work only within 'vi'. (10 Replies)
Discussion started by: harishmitty
10 Replies

8. UNIX for Dummies Questions & Answers

how to open a text file using some tool such as gedit under gtk

how to open a text file using some tool such as gedit under gtk I list some text file names in a GtkCList . I want to open the file on when users click on the row. How to implement this ? Thanks (0 Replies)
Discussion started by: cy163
0 Replies

9. UNIX for Dummies Questions & Answers

pdf to text

Hi, Can anyone help me in converting a PDF file into a text file? Thanks, sskb (2 Replies)
Discussion started by: sskb
2 Replies
Login or Register to Ask a Question