Advertisement
metalx1000

IMAGE and TEXT into a PDF

Feb 23rd, 2018
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.81 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Copyright Kris Occhipinti
  4. #Feb 23th 2018
  5. #https://filmsbykris.com
  6. # Licensed under the AGPLv3 https://www.gnu.org/licenses/agpl-3.0.txt
  7. #Finds text in an image and puts
  8. #both the image and the text into a PDF file
  9.  
  10. #requirements
  11. #apt-get install xpdf tesseract enscript ghostscript poppler-utils
  12.  
  13. img="$1"
  14. base="$(echo "$img"|cut -d\. -f1)"
  15.  
  16. echo "Working with $base..."
  17.  
  18. #image to pdf
  19. convert "$img" "${base}_1.pdf"
  20.  
  21. #find text in img
  22. tesseract "$img" -|sed '/^\s*$/d' > "$base.txt"
  23. #pandoc "$base.txt" -o "${base}_2.pdf"
  24. enscript -p "${base}.ps" "${base}.txt"
  25. ps2pdf "${base}.ps" "${base}_2.pdf"
  26.  
  27. #create final PDF
  28. pdfunite "${base}_1.pdf" "${base}_2.pdf" "${base}.pdf"
  29.  
  30.  
  31. #clean up
  32. rm "${base}.ps" "${base}.txt" "${base}_1.pdf" "${base}_2.pdf"
  33.  
  34. #display output
  35. xpdf "${base}.pdf"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement