Eskil

Check-in [4792598887]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Support pdftotext flags in pdf plugin
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4792598887c4ec895e254135a6ef7fccd6a735d07dd8dac1bcb23a2306aadf6a
User & Date: peter 2021-02-28 15:36:42.683
Context
2021-02-28
15:37
Log View support for Fossil check-in: b9f391ecdb user: peter tags: trunk
15:36
Support pdftotext flags in pdf plugin check-in: 4792598887 user: peter tags: trunk
15:36
Ballonhelp within frame check-in: 1bd10af7e2 user: peter tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to plugins/pdf.tcl.
1





2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20












21
22
23
24
25
26
27
28
##Eskil Plugin : Compare text from PDF files. (needs pdftotext)





#
# This plugin runs input through the external tool pdftotext.
# Thus it must be run together with the -pluginallow flag.
# Anything given in -plugininfo is passed as parameters to pdftotext.

# Example file for a plugin.
# A plugin's first line must start exactly like this one.
# The text after : is the summary you can get at the command line

# A plugin must define this procedure to do the job.
# side: left or right
# chi:  An input channel for reading the original file.
# cho:  An output channel for writing the processed file.
proc PreProcess {side chi cho} {
    if {[info commands exec] eq ""} {
        puts $cho "PDF plugin must be run with privilege to be able\
                   to execute pdftotext"
        return 1
    }












    set cands [auto_execok pdftotext]
    lappend cands [file join $::WhoAmIFull pdftotext]
    lappend cands [file join $::WhoAmIFull .. pdftotext]
    lappend cands [file join $::WhoAmIFull .. .. pdftotext]
    set found 0
    foreach cand $cands {
        if {[file exists $cand]} {
            set found 1
|
>
>
>
>
>



<















>
>
>
>
>
>
>
>
>
>
>
>
|







1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
##Eskil Plugin : Compare text from PDF files. (needs pdftotext 4+)
## Option -marginl : Left margin to pass to pdftotext
## Option -marginr : Right margin to pass to pdftotext
## Option -margint : Top margin to pass to pdftotext
## Option -marginb : Bottom margin to pass to pdftotext
## Option -pdftotext : Extra options to pass to pdftotext
#
# This plugin runs input through the external tool pdftotext.
# Thus it must be run together with the -pluginallow flag.


# Example file for a plugin.
# A plugin's first line must start exactly like this one.
# The text after : is the summary you can get at the command line

# A plugin must define this procedure to do the job.
# side: left or right
# chi:  An input channel for reading the original file.
# cho:  An output channel for writing the processed file.
proc PreProcess {side chi cho} {
    if {[info commands exec] eq ""} {
        puts $cho "PDF plugin must be run with privilege to be able\
                   to execute pdftotext"
        return 1
    }
    set opts(-marginl) ""
    set opts(-marginr) ""
    set opts(-margint) ""
    set opts(-marginb) ""
    set opts(-pdftotext) ""
    foreach opt {-marginl -marginr -margint -marginb -pdftotext} {
        set i [lsearch -exact $::argv $opt]
        if {$i >= 0} {
            incr i
            set opts($opt) [lindex $::argv $i]
        }
    }
     set cands [auto_execok pdftotext]
    lappend cands [file join $::WhoAmIFull pdftotext]
    lappend cands [file join $::WhoAmIFull .. pdftotext]
    lappend cands [file join $::WhoAmIFull .. .. pdftotext]
    set found 0
    foreach cand $cands {
        if {[file exists $cand]} {
            set found 1
38
39
40
41
42
43
44
45











46
47
48
49
50
51
52
53
54
55
    if { ! $found} {
        puts $cho "PDF plugin needs external tool 'pdftotext' to run"
        return 1
    }
    if {[catch {llength $::Info}]} {
        puts $cho "PDF plugin needs -plugininfo parameter to be a list"
        return 1
    }











    # Use source file with pdftotext since stdin is not reliable on e.g Windows
    if {[catch {exec $cand {*}$::Info $::File($side) - >&@ $cho}]} {
        puts $cho "**************************************"
        puts $cho "PDF plugin got an error from pdftotext"
    }

    # Signal that the file after processing should be used both
    # for comparison and for displaying.
    return 1
}








>
>
>
>
>
>
>
>
>
>
>

|








54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    if { ! $found} {
        puts $cho "PDF plugin needs external tool 'pdftotext' to run"
        return 1
    }
    if {[catch {llength $::Info}]} {
        puts $cho "PDF plugin needs -plugininfo parameter to be a list"
        return 1
    }
    if {[catch {llength $opts(-pdftotext)}]} {
        puts $cho "PDF plugin needs -pdftotext parameter to be a list"
        return 1
    }
    # Pass options from -plugininfo as well.
    set options [concat $::Info $::opts(-pdftotext)]
    foreach opt {-marginl -marginr -margint -marginb} {
        if {$opts($opt) ne ""} {
            lappend options $opt $opts($opt)
        }
    }
    # Use source file with pdftotext since stdin is not reliable on e.g Windows
    if {[catch {exec $cand {*}$options $::File($side) - >&@ $cho}]} {
        puts $cho "**************************************"
        puts $cho "PDF plugin got an error from pdftotext"
    }

    # Signal that the file after processing should be used both
    # for comparison and for displaying.
    return 1
}