Note: here suggest that the program GUI DiffPDF that allows a better comparison between two PDF documents. A simple method to compare two documents in PDF format is to exploit the combination (To convert PDF to text pure) + diff (to see the differences). I was tired of performing all the usual commands then I wrote this script fresh fresh: # / bin / bash convert function () { txt = $ ( eval "expr \\ $" $txt = $ (
1
")
pdf = $ ( eval" expr \\ $ "$ 2 " )
choice = "" while [ -f "$ txt" ] do
read -p "$ txt file already exists, overwrite? [Y / n]:"
choice case "$ choice " in
s then exit
1 fi eval
"$ 1 = $ txt"
}
if
[$ #-ne 2]; then echo
"Usage: $ 0 PDF1 PDF2 "
exit 1 fi
pdf1 = $ 1 pdf2
= $ 2
txt1 = $ (dirname
" $ pdf1 ") / $ (
basename "$ pdf1"
. pdf). txt2 txt = $ (dirname
"$ pdf1" ) / $ (
basename "$ pdf2" . Pdf). txt convert convert txt1 pdf1 & & txt2 pdf2
if [$? -Eq 0];
then diff-u "$ txt1"
"$ txt2" an abbreviation of the current user's home folder), possibly creating it if it does not exist. Give the command in the terminal .
~ /. profile (for the curious used to load the file ~ /. profile which adds the folder $ HOME / bin the environment variable $ PATH ), then this should be sufficient to give the terminal command
pdf-diff / path / to / first / your / path / to / second / file (or the name you gave to the script). will not be perfect, it has all the limitations that exist in the transition from a PDF to a plain text file (for example if an image change does not notice and the success of the comparison depends on how well pdftotext unable to read the documents) but is quite fast and I found this system often very useful. I also wrote the script corresponding
Nautilus (using zenity
):
# / bin / bash
title = "Comparing PDF" function
convert () {
eval "expr \\ $" $ 1 ") pdf = $ (eval"expr \\ $" $
2 ") while [-f" $ txt "
]
do
if
! zenity - question - title = "$ title" -
text = "$ txt file already exists, overwrite?" ; then
txt = $ ( zenity - entry - title = "$ title" - text = 'Specify a different output file: ")
else
break 2 fi
done
pdftotext "$ pdf" "$ txt" homes $? in 0)
;; 1) zenity - error - title = "$ title" - text = "There was an error opening $ pdf." exit 1 ;;
2) zenity - error - title = "$ title" - text = "There was an error opening $ txt."
exit 1 ;; 3) zenity - error - title = "$ Title" - text = "There was an error related permits $ pdf."
exit 1 ;; *) zenity - error - title = "$ title" - text = "There was an error!"
exit 1 esac
eval "$ 1 = $ txt"}
if [$ #-ne 2];
then zenity - error - title = "$ title" -
text = "You must select two files at a time"
exit 1 fi
pdf1 = $ 1
pdf2 = $ 2
txt1 = $ (dirname
"$ pdf1" ) / $ (basename " $ pdf1 "
. pdf). txt2
txt = $ (dirname
" $ pdf1 ") / $ (basename
" $ pdf2 ". pdf). txt convert txt1 pdf1 & & ; convert txt2 pdf2
if [$? -Eq 0];
then diff-u "$ txt1"
"$ txt2"
- filename = / dev / stdin rm-f "$ txt1" "$ txt2"
else #
should not ever come here, to put safety
zenity - error - title = "$ title" -
text = "There was an error!" exit 1 fi
exit 0
To use this second script open a blank file with a text editor, copy the script editor and save it in the folder ~ / .gnome2/nautilus- calling scripts, for example, " Compare PDF . Make it executable and then script. So you can select and compare two PDF files by clicking the right button, choose Script → Compare PDF (or the name you gave to the script).
From a technical standpoint, the script of which looks a bit 'particular: the function converter (which is used to convert PDF to text and make the appropriate checks) has a sort of passing variable by reference and not by value. The trick is to convert the function not the value of the variable but its name (those familiar with other programming languages \u200b\u200bmay find it natural). Details can be seen here: # http://www.pluto.it/files/ildp/guide/abs/functions.html DEREFERENCECL .
0 comments:
Post a Comment